Recvfrom and multiple clients from the same host

Started by
2 comments, last by KnolanCross 11 years, 4 months ago
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.

Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).

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.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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.
enum Bool { True, False, FileNotFound };

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);

Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).

This topic is closed to new replies.

Advertisement