Page Personnelle de Vincent Kerhoas
Vincent Kerhoas
Enseignant du Supérieur
Professeur Agrégé
Page Personnelle de Vincent Kerhoas

Network UDP TCP Sockets

Back                  << Index >>

A few illustrated reminds about UDP TCP sockets.
For complete explanations, please have a look at : https://www.enib.fr/~harrouet


Every following examples can be downloaded here :



CODE

just write ‘make’ in a terminal to compile all of them.


IP address


UDP text

Considering we have a Linux PC + another Linux PC or Rasperry PI :

udp_txt

If you want to test with one PC ( with local adress 127.0.0.1) , consider this drawing :

udp_txt


UDP bin

Datas are not necessarly characters ; sending binary datas supposes knowing byte order.
That’s the purpose of htonl and ntohs functions.


UDP Select server

Since the receive function is blocking, the SELECT function permits switching between several incoming sources.

udp_select

  
prog04_select.c

TCP mono server

TCP is a CONNECTED protocole, so before sending and receiving datas, the server must accept a client connection request.
For the moment the actual client must end the connection before the server accepts a new client.

tcp_mono


TCP Select server

The Select Function permits switching between several sockets and listening for new TCP connections.

tcp_select_1

tcp_select_2

  
prog05_tcp_select_server.c

TCP Thread server

A more flexible server than the ‘select’ one : allowing a thread for each client.
The FOR loop in the main() wait on new connection requests.

tcp_thread_1

tcp_thread_2

tcp_thread_3

  
prog05_tcp_thread_server.c

Back                  << Index >>