i am trying to write udp chat server in c language. i have written tcp chat server before and it is ok.
in tcp server, accept function returns an fd number and server communicate with a specific client according to this fd number.
but in udp, how can i listen a specific client?
In my tcp server, after a client connect to server, a thread is created and it listen this client. So for each client, there is a thread that listen to according to fd number that is returned from accept function. so any message can send according to this fd number to specific client.
How can i achieve this in udp server?
Thanks for answers.
You use
recvfromto find out the source IP/port and then reply withsendto. You only need tobindto select a server port. You don’taccept. Allconnectdoes for UDP is set the default destination (which you plan to override withsendto).