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

Started by
3 comments, last by awg_x 17 years, 9 months ago
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?)
Advertisement
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.



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

Use recvfrom() to receive data from clients. Use sendto() to send data to clients. Use only a single socket.
enum Bool { True, False, FileNotFound };
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 :)

This topic is closed to new replies.

Advertisement