# UDP Sockets

Assim como TCP socket, **UDP**, ou *User Datagram Protocol*, também precisa estar associado a uma porta de rede. E igualmente TCP, UDP também é full-duplex.

Por outro lado, UDP não estabelece uma conexão, ou seja, não utiliza *stream sockets*, mas **datagram sockets,** e portanto não tem as garantias de entrega do TCP.

Vamos criar um server UDP, lembrando que precisamos indicar a opção `-u` para que seja um socket **datagram**.

```bash
## Server
$ nc -ulv 8080
Bound on 0.0.0.0 8080
```

E do lado do cliente, indicando o endereço do server (localhost) e porta de rede:

```bash
## Client
$ nc -uv localhost 8080
Connection to localhost (127.0.0.1) 8080 port [udp/*] succeeded!
```

Confirmando com `lsof` as portas utilizadas:

```bash
$ lsof -i udp:8080
COMMAND  PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
nc      1325 root    3u  IPv4 7313683      0t0  UDP localhost:8080->localhost:59986
nc      1328 root    3u  IPv4 7313715      0t0  UDP localhost:59986->localhost:8080
```

* um processo para representar as mensagens escritas do server para o client
* outro processo para representar as mensagens escritas do client para o server

### Resumo

É isto. Esta seção teve por objetivo explicar e explorar utilização de **UDP sockets**.&#x20;

Nas próximas seções, vamos continuar com o objetivo inicial deste guia, e começar a *construir um Web server* aplicando estes conceitos, com o intuito de demonstrar os fundamentos da Web.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://web101.leandronsp.com/internet/udp-sockets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
