Click here to Skip to main content
14,975,411 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I am writing code for NTP client using datagram socket. In which I want to use three servers for timestamp. Is it possible to connect one client to three servers using same socket and port?

1 solution

Since datagrams are connectionless, it should be easy to share the same port. Just be sure to label it as a shareable port when establishing the socket. As for using the same socket, well, you should be able to do that based on the connectionless premise, since you essentially open the socket and wait for data (usually the datagram will contain information regarding source, but you can easily enough just receive data from multiple sources).

Edit: You only need a shareable port if there's multiple applications using it. If there's only one application, you don't need that although it's usually easier to work with in Linux due to socket timeouts being somewhat unpredictable.
r.chovatiya 4-Apr-14 1:25am
@Albert : Yup, correct. Linux socket timeout is unpredictable thats why I am looking for this. Anyway thank you for your answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900