Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Okay - I was expecting to find a lot of documentation on this problem but oddly enough I seem to be coming up pretty blank...

 

I am creating a SERVER / CLIENT network game - in this game the client will send a UDP "HELLO|XXX.XXX.XXX.XXX" message to the SERVER - the server will respond to the client with a "HEY|XXX.XXX.XXX.XXX". Then both client and server will form TCP connections using these IP-Addresses.

Now this works fine in my LAN (of course) but when I try to play online it doesn't work for one obvious reason, the IP-Address sent back-and-forth is the LAN IP and since I have a router it is not my REAL internet ip-address...

I use the following code to determine my CLIENT & SERVER ip-addresses...

IPAddress ipServer = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];

This code returns stuff like "192.168.0.1", "192.168.0.2", etc.. (which is perfect for my LAN gaming)....

 

Is there maybe a way to get the IP-Address from the incoming UDP packet instead of explicitly sending it?

I use the following code to receive, I think in java (way-back-when) there was a way to get the ip-address of the person who sent the data from the socket? (could be wrong)

int nReceived = sktServer.ReceiveFrom(buffer, ref epSender);

 

Or a way to maybe loop to my router somehow to get my actual WAN (internet) ip-address?

How do people usually solve this problem? I assume it is encountered fairly often in the real world....

 

Any ideas, hints, and help would be greatly appreciated, thanks

Posted

Difficult to do under setups where you are behind a router/gateway. I finally "cheated" by making a PHP webpage that simply returns the IP address of the vistor to the page. This seemed to be the only realistic way to do it.

 

Hopefully in the future router/gateways will have a common WAN IP return call that can be made. Kind of doubt that though.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...