C Program Using Udp Sockets
Since this has 21K views with no explicit answer, and it is basic understanding of coding for UDP. Brother Lh4 B814 Manual. I will give it some love.
Introduction to Sockets Programming in C using TCP/IP Professor. TCP sockets UDP sockets TCP ports UDP ports Descriptor references Sockets bound to ports. Send a UDP datagram in C. Construct the remote socket address. To send a UDP datagram it is necessary. Unix Network Programming, Volume 1: The Sockets.
As mentioned in the comments already: In your server code, you receive a message from the client using: recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen)) The result of this function is that the message data will be written into buf and the ip address and port number of the socket that sent the message will be filled into si_other (which must be of type struct sockaddr_in). So then, when you send a response using: sendto(s, buf, recv_len, 0, (struct sockaddr*) &si_other, slen) Since si_other, which you are passing as the destination address for sendto, contains the ip/port of the last message you got, the response will always go back to the sender of the last message you got. In many server applications this is a pretty common scenario: you get a request from somewhere, you send a response back to the same place.
If you want the message to go someplace else, other than the process that sent you the request, then you need to create a different struct sockaddr_in variable which contains the ip address and port of where you would like the message to go. And in your client code, you already have the code that does that, eg (cleaned up a bit): struct sockaddr_in si_client2; memset((char *) &si_client2, 0, sizeof(si_client2)); si_client2.sin_family = AF_INET; si_client2.sin_port = htons(CLIENT2_PORT); if(inet_aton(CLIENT2_HOST, &si_client2. Putumayo Presents Samba Bossa Nova Rar Files. sin_addr) == 0) perror('inet_aton'); So now, if you use si_client2 in your sendto(), the packet will go to that client.