Shaitan00 Posted October 25, 2006 Posted October 25, 2006 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 Quote
Administrators PlausiblyDamp Posted October 25, 2006 Administrators Posted October 25, 2006 http://www.xtremedotnettalk.com/showthread.php?t=79544 might be worth a look as it discusses this issue. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mooman_fl Posted October 27, 2006 Posted October 27, 2006 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. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.