# std.net

Blocking TCP and UDP socket primitives.

```tea
use net from "std.net"
```

Examples may be fragments requiring the module import or additional setup.

## std.net.tcp_connect

```tea
pub def tcp_connect(address: String) -> TcpConnection
```

Connect to a TCP server address such as "127.0.0.1:8080".

## std.net.tcp_bind

```tea
pub def tcp_bind(address: String) -> TcpListener
```

Bind a TCP listener to an address such as "127.0.0.1:0".

## std.net.tcp_accept

```tea
pub def tcp_accept(listener: TcpListener) -> TcpConnection
```

Accept one inbound TCP connection.

## std.net.tcp_read

```tea
pub def tcp_read(connection: TcpConnection, bytes: Int) -> List[Int]
```

Read up to the requested number of bytes from a TCP connection.

## std.net.tcp_read_text

```tea
pub def tcp_read_text(connection: TcpConnection, bytes: Int) -> String
```

Read up to the requested number of bytes as UTF-8 text with lossy decoding.

## std.net.tcp_write

```tea
pub def tcp_write(connection: TcpConnection, data: List[Int]) -> Int
```

Write bytes to a TCP connection and return the number of bytes written.

## std.net.tcp_write_text

```tea
pub def tcp_write_text(connection: TcpConnection, text: String) -> Int
```

Write UTF-8 text to a TCP connection and return the number of bytes written.

## std.net.tcp_set_read_timeout

```tea
pub def tcp_set_read_timeout(connection: TcpConnection, milliseconds: Int) -> Void
```

Set a TCP read timeout in milliseconds. Use 0 to clear the timeout.

## std.net.tcp_set_write_timeout

```tea
pub def tcp_set_write_timeout(connection: TcpConnection, milliseconds: Int) -> Void
```

Set a TCP write timeout in milliseconds. Use 0 to clear the timeout.

## std.net.tcp_close

```tea
pub def tcp_close(connection: TcpConnection) -> Void
```

Close a TCP connection handle.

## std.net.tcp_close_listener

```tea
pub def tcp_close_listener(listener: TcpListener) -> Void
```

Close a TCP listener handle.

## std.net.udp_bind

```tea
pub def udp_bind(address: String) -> UdpSocket
```

Bind a UDP socket to an address such as "127.0.0.1:0".

## std.net.udp_connect

```tea
pub def udp_connect(socket: UdpSocket, address: String) -> UdpSocket
```

Connect a UDP socket to a default peer address.

## std.net.udp_send

```tea
pub def udp_send(socket: UdpSocket, data: List[Int]) -> Int
```

Send bytes through a connected UDP socket.

## std.net.udp_send_text

```tea
pub def udp_send_text(socket: UdpSocket, text: String) -> Int
```

Send text through a connected UDP socket.

## std.net.udp_send_to

```tea
pub def udp_send_to(socket: UdpSocket, data: List[Int], address: String) -> Int
```

Send bytes to a UDP peer address.

## std.net.udp_send_text_to

```tea
pub def udp_send_text_to(socket: UdpSocket, text: String, address: String) -> Int
```

Send text to a UDP peer address.

## std.net.udp_recv

```tea
pub def udp_recv(socket: UdpSocket, bytes: Int) -> List[Int]
```

Receive bytes from a connected UDP socket.

## std.net.udp_recv_text

```tea
pub def udp_recv_text(socket: UdpSocket, bytes: Int) -> String
```

Receive text from a connected UDP socket with lossy UTF-8 decoding.

## std.net.udp_recv_from

```tea
pub def udp_recv_from(socket: UdpSocket, bytes: Int) -> UdpPacket
```

Receive bytes and the sender address from an unconnected UDP socket.

## std.net.udp_recv_text_from

```tea
pub def udp_recv_text_from(socket: UdpSocket, bytes: Int) -> UdpTextPacket
```

Receive text and the sender address from an unconnected UDP socket.

## std.net.udp_set_read_timeout

```tea
pub def udp_set_read_timeout(socket: UdpSocket, milliseconds: Int) -> Void
```

Set a UDP read timeout in milliseconds. Use 0 to clear the timeout.

## std.net.udp_set_write_timeout

```tea
pub def udp_set_write_timeout(socket: UdpSocket, milliseconds: Int) -> Void
```

Set a UDP write timeout in milliseconds. Use 0 to clear the timeout.

## std.net.udp_close

```tea
pub def udp_close(socket: UdpSocket) -> Void
```

Close a UDP socket handle.
