UDP server - client communication

Sep 5, 2008 at 6:51pm
Hello.

I'm developing a generic UDP server. After creating the socket (SOCK_DGRAM) I call bind and then I start looping with recvfrom function. Inside the loop I try to respond to the incoming peer with sendto function (after launching another thread that uses another socket to respond) but the peer doesn't recives anything.

I am testing it with a simple code UDP client that creates the socket, calls a sendto that reaches OK to the server, and then gets stuck in the recvfrom function.

What am I doing wrong? I think that the problem resides in making another socket for the server response :S


Regards
Sep 5, 2008 at 8:25pm
Are you using the accept() to accept the incoming connection before you are sending or receiving the data?
Sep 5, 2008 at 8:58pm
For the server side - after the bind, he should listen, once listen returns he should accept then use the socket from the accept to communicate to the client that connected.

If you are interested in doing tcp/ip internet stuff like this, a good guide is this one:
http://beej.us/guide/bgnet/
Last edited on Sep 5, 2008 at 8:59pm
Sep 5, 2008 at 9:58pm
Thanks for the replies but the protocol is UDP, not TCP... so the server doesn't need to use listen() because there is no connection between server and client in UDP. For the same reason accept() doesn't work.

Regards.
Sep 5, 2008 at 10:17pm
Oh doh, sorry. You could try googling C++ UDP and see what you get, I haven't worked with UDP so I can't really help you, sorry.
Topic archived. No new replies allowed.