Sheetal Singala
Sheetal Singala

Reputation: 5

Socket programming in UDP

I have 2 servers and a client. There is 2 way communication between the server and the client. Would I need multiple sockets on the client to communicate with the servers? I used only one socket and a few of the packets from the servers are missing. How many sockets would I need to communicate with the server?

Upvotes: 0

Views: 68

Answers (1)

Jeremy Friesner
Jeremy Friesner

Reputation: 73081

With UDP you almost always only need a single socket; you can call sendto() and recvfrom() on it to send and receive UDP packets from anywhere.

As for missing UDP packets, that is a fact of life with UDP; UDP packets can and sometimes will get dropped at any step of the path from sender and receiver. You'll need to design your app to tolerate that, or alternatively come up with a mechanism by which the receiver can detect that a packet was lost and request a resend (or otherwise somehow handle that situations).

Upvotes: 1

Related Questions