Jump to content
  • Advertisement
Sign in to follow this  
KnolanCross

Recvfrom and multiple clients from the same host

This topic is 2206 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I am creating a small side project, it is yet another UDP with confirmation solution.
I am using C on linux, trying to remain as close to POSIX as possible, so I won't have a hard time porting it to windows.

Right now I am facing the following problems:

1) Client A and Client B are behind a router, so I receive their messages (using recvfrom) and their addr struct show the same IP. Is there any API provided information that I can use I should I implement some kind of handshake where I can give each of them a random number to identify them?

2) Whenever I receive the first message from some IP, the address returned is FFFFFFFF. Any ideas?

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
For the first question, this is a natural consequence of how NAT works. If you want to uniquely identify endpoints behind NAT, you will need to assign them some kind of identifier yourself besides just address.

The second question just sounds like a bug in the way you use the APIs; if you could post some (minimal) code that reproduces the problem that'd be helpful.

Share this post


Link to post
Share on other sites
While client A and client B will have the same IP address, they will have different source ports.
Think about it: If there was no way to tell them apart, how could the router know which return packet to send to which client?
Thus, you can simply identify the clients with their remote IP:port tuple, just like with any other clients.

Share this post


Link to post
Share on other sites

While client A and client B will have the same IP address, they will have different source ports.
Think about it: If there was no way to tell them apart, how could the router know which return packet to send to which client?
Thus, you can simply identify the clients with their remote IP:port tuple, just like with any other clients.


Lol, that was really obvious. I feel stupid now lol.
Thanks a lot hplus.

EDIT:
2nd problem solved.
In case anyone find this with the same problem I had, you need to start the addrlen with sizeof(struct <your address type); Edited by KnolanCross

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!