Udp Socket Interface
Udp Socket Interface
Datagram socket
UDP header
The function sequence of Datagram socket programming
UDP lost datagrams and error handling
Brief comparison of 2 types of socket programming
Create socket
bind, connect
listen, accept (TCP only)
send and receive data
We use INADDR ANY so that our socket will bind to any of the local
addresses that are configured, and we use the port number that was
passed as an argument.
/* set up the server address and port */
/* use INADDR_ANY to bind to all local address
udpServer.sin_family = AF_INET;
udpServer.sin_addr.s_addr = htonl(INADDR_ANY);
/* use the port passed as argument */
udpServer.sin_port = htons(atoi(argv[1]));
// atoi converts ascii to integer
struct sockadd in must be filled with the server’s address and its
well-known port number.
A datagram socket is needed
The client’s sockaddr in structure is set up with the requried
information.
A specific port number for the client is not needed. The operating
system will assign one.
The client will use the sendto() function to send request to the server.
If the value we get back from the call to sendto() tells the request
was sent, the client gets ready to receive the server’s response using
recvfrom() function.