Sockets
The socket as a communication end, the TCP stream and UDP datagrams, the server calls (socket, bind, listen, accept) and the client calls (socket, connect), send and recv, sendto and recvfrom, and network byte order.
- 31 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- The numbers
- On the diagram
A few cards from the deck
Socket: what is it?
Show the answer
A communication endpoint handled through a descriptor, identified by an IP address, a port number and a transport protocol.
Like a file or a pipe, it is read and written through descriptors. It is obtained with
socket(AF_INET, SOCK_STREAM, 0)for TCP andSOCK_DGRAMfor UDP.What should replace the question mark to read what the client sent?
```c
int ecoute = socket(AF_INET, SOCK_STREAM, 0);
bind(ecoute, (struct sockaddr *)&adresse, sizeof adresse);
listen(ecoute, 5);
int client = accept(ecoute, NULL, NULL);
char buf[100];
ssize_t n = recv(?, buf, sizeof buf, 0);`clientecouteecoute, after a second accept0, the server's standard input
Show the answer
clientacceptreturnedclient, the service socket for this exchange. The listening socket only serves to accept connections: callingrecvon it gives the “Transport endpoint is not connected” error.On a TCP server, the call order is socket, …, …, …; the client simply chains socket then connect.
Show the answer
On a TCP server, the call order is socket, bind, listen, accept; the client simply chains socket then connect.
bindsets the local address,listenopens the waiting queue,accepttakes a client from it. The client does not callbind: the system gives it an ephemeral port.