Skip to main content
gamedev.net
🔒 Locked

Need Help!

Started by Robinhood 7 replies 1.1k views
Original Post
Robinhood
Robinhood
Hello,everyone.I have got a problem on UDP. When two of clients from the same subnet connect to my server,my server will not send the reponse back immediately and it should take time to process the data. My question is how do I send the reponse back when two clients seem to have the same IP address.(should I store each address for each request?). Thank you in advance!
Lord Bart
Lord Bart
Hello Robinhood,

Using UDP, then you are using ether recvmsg or recvform in your server.
You should have the info supple by those calls as to who sent the buffer you just read.

Just pass this along with your buffer, and then when the server has a response back use this data to send back to client.

Should really be no problem.

You say same ip address? do you mean you had 2 clients running on same system? I still believe the info you get back has enough info to send to the proper clients connection.

Remember a Client has it own socket connection even if you UDP, but the Server doesn't.
So UDP protocol should route it back to it own socket.
I could be wrong but I don't think so.

Just use the info you got form recvmsg or recvform and you should be fine.

Lord Bart :)
Robinhood
Robinhood
2 Clients share the same IP is something like connection from the same Net bar or from the same LAN.
when the server receives packets by recvfrom,it will not send the reponse back until another Message.then how?
cbenoi1
cbenoi1
> two clients seem to have the same IP address

That could be normal if both computers are plugged through the same router or you have two instances of the client app on the same computer. But each client should have its own port number. The IP and port number are used to distinguish connections in both the routers and the computers.

-cb
Robinhood
Robinhood
Do you mean that when the server UDP socket binds a port,the client UDP sockets through the same router use different ports to communicate with the server UDP socket?
It seems that sendto() func uses the same port to communicate with the server UDP socket.
cbenoi1
cbenoi1
If you try to bind the same port on the same machine, you will get an error. If 2 machines plugged on the same router bind to the same port number locally, the router will remap the ports on the WAN side so that the end result being that the two machine, from the outside world's perspective, will be bound to 2 different ports. The router will keep the remapping active as long as there is traffic. After a few minutes of inactivity, the remapping on the inactive port will be removed. That's the NAT part of a router's functionality: Network Address Translation.

-cb
Lord Bart
Lord Bart
Hello Robinhood,

I believe that when you do a connection in UDP and you send packets to a host (not broadcast) the packet has info in it about the client host and port so you can answer it back. When it hits a router it should in the process of routing keep that info about client system ip and port each udp message is coming form and pass it along.

Now if you sending it broadcast I still think it has sending host ip and port but not sure.

How else would you ever be able to send UDP on the Internet, if you replace sending host ip and port, you could never answer back.

Now cleints behind a firewall will have same host ip and port because the firewall hide the client ip and uses it own ip.
So in that case yes client could look like they are on the same ip.
But the firewall takes care of the mapping for you.
Maybe it is doing this.

client behind a firewall connects to server on port 2000.
This goes out to firewal which then trys it own connection to serve on port 2000 will it connects it then return a connection to client.
This way the client gets a connection though the firewall and firewall take care of relaying UDP messages. The server only see firewalls ip and port client thinks it connected to server but is actual connected to firewall.

Not sure it works lke this but I could see it working this way. :)

Lord Bart :)
cbenoi1
cbenoi1
> Not sure it works lke this but I could see it working
> this way. :)

Hey Bart, I could not understand your explanation. I reread mine and could not understand my own explanation either...(DOH!)

Fortunately, there are better explanations about NAT operations and port mapping on the web, including pictures, like this one here:

http://www.microsoft.com/technet/prodtechnol/winxppro/deploy/nattrnsv.mspx


-cb
Robinhood
Robinhood
Thank you for helping me and now I know how NAT works.
Is there any UDP class available on internet?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.