Sign in to follow this  

How to send an UDP message from a server through a DSL-router to the client

This topic is 4165 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 all, my setting is: A client behind a DSL-router sends an UDP login-message to a server in the internet, which is behind a router(the router routes all messages which arrive at an unique port number to the server). The server gets the message, by using a socket object, which is bound to the unique port number and sends back a confirmation message to the client(the clients DSL-router). The client receives the confirmation-message from the DSL-router successfully! My problem begins, when a second client send a message to the server and the server has to send this message to the first client(My server receives all messages with only one, never changing UDP socket object). I created a new socket object with the ip address and port number of the first client (= the first clients router). But when I send this message by using the new socket object, the first client gets no message. I think the router of the first client blocks the message from the server. But how to get this new message through the DSL-router back to the first client? Anyone has a helping hand? (All I know is, that "The Saga Of Ryzom" uses UDP only, so somehow it should be possible, but how?)

Share this post


Link to post
Share on other sites
Why are you creating more than one socket? Generally the server only needs to create one for UDP unless you're servicing multiple listening ports. You normally want to talk to the client on the same socket in which he established contact.

Share this post


Link to post
Share on other sites


When you create the new socket on server, that socket obtains a new port. When you send data to the first client from the new socket the router rejects the packet, because its coming from a port that the client has never contacted before. You need to send the data to the client from the old socket, because client's router only trusts that socket's port (since the client has already sent data to that port).

Share this post


Link to post
Share on other sites
Many thanks to all three, who answered my question! =D

The tip to "Use only a single socket." made my day!

I have to explain, that I use the "DataReel Open Source - A cross-platform database and communications toolkit." at

http://www.datareel.com


From this library I use the gxSocket class. I created a second gxSocket object for the answer to the other clients, because the gxSocket class misses two important methods:
1. A method for setting a new remote port in a gxSocket object.
2. A method for setting a new remote IP address in a gxSocket object.

But it is possible to set these two, when using a constructor of this class, so I created a second gxSocket object. Second reason why I did it, was because I have no networking book, which explains the coherences to me.

I didn't noticed, that what I did was the wrong way, because for a long time I only tested my game in a LAN, so no player was somewhere in the internet and when all clients are in the same LAN, the game works flawlessly.


Now I simply wrote the two missing methods myself and the game exactly does, what I want it to do. =D


So again many, many thanks to all of you!!!
I'll contact the authors of the datareel library, maybe they include my two missing methods into the gxSocket class?
We'll see...


Greetings
Alex :)

Share this post


Link to post
Share on other sites

This topic is 4165 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this