UDP programming questions/problems

Goi

Diamond Member
Oct 10, 1999
6,771
7
91
Hi,
I'm trying to create a very simple client server program under unix/linux that sends packets/msgs of arbitary sizes from the client to the server over a LAN. Right now I'm trying to send a simple "Hello" string from the client to the server, and have the server print it on screen, and this works if the client and server programs are running on the same machine and the host.sin_addr.s_addr(where host is either the client or server) is set to the same value (either inet_addr("127.0.0.1") or inet_addr("ip address")). However, if they are running on different machines on the same network, the server doesn't seem to receive the string. I've changed the host.sin_addr.s_add to the appropriate values(dotted decimal) but this doesn't seem to work. sendto() isn't giving me an errno either, so I don't know what's wrong.

Any ideas on why this isn't working?

Thanks!
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Have you started up a packet sniffer on both machines to see if the packet really makes it there?
 

Goi

Diamond Member
Oct 10, 1999
6,771
7
91
Here are snippets from my client and server program, the important parts:

Client code:
struct sockaddr_in peer;
int udp_socket;
peer.sin_family = AF_INET;
peer.sin_port = htons(8765);
peer.sin_addr.s_addr = inet_addr("server ip");
udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
sendto(udp_socket, "Have a nice day!\n", 17, 0, (struct sockaddr *)&peer, sizeof(peer));

Server code:
int udp_socket;
struct sockaddr_in peer;
peer.sin_family = AF_INET;
peer.sin_port = htons(8765);
peer.sin_addr.s_addr = inet_addr("client ip");
udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
bind(udp_socket,(struct sockaddr *)&peer,sizeof(peer));
peerlen=sizeof(peer);
while(1) {
retval = recvfrom(udp_socket, recvbuffer, sizeof(recvbuffer), 0, (struct sockaddr *)&peer, &peerlen);
if (retval != -1) {printf("%s", recvbuffer);}
}


I'm not sure how to start a packet sniffer on the machines...