UDP data transfer hangs on recvfrom

J

Jack

Hi guys,
I can't figure this out.

rec = recvfrom(sdUDP, buf, BUFSIZE, 0, (struct sockaddr
*)&connectChannel, &chanSizeUDP );
while(1){
if (rec > 0){
snt = sendto(sdUDP, buf, rec, 0, (struct sockaddr
*)&connectChannel, chanSizeUDP );
rec = recvfrom(sdUDP, buf, BUFSIZE, 0, (struct sockaddr
*)&connectChannel, &chanSizeUDP );
}
else{
stats();
exit(0);
}
}

The above is the code from a UDP server. The server is suppose to
simply read the incoming data from the buffer and echo it back to the
client. For some reason the code hangs on the recvfrom inside the
while loop. I don't know why this happens... The client sends and
receives the data but the server never exits.

Any ideas..
 
T

Thomas J. Gritzan

Jack said:
Hi guys,
I can't figure this out. [...socket stuff...]
The above is the code from a UDP server. The server is suppose to
simply read the incoming data from the buffer and echo it back to the
client. For some reason the code hangs on the recvfrom inside the
while loop. I don't know why this happens... The client sends and
receives the data but the server never exits.

Read here:
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top