Advertisement

Troubles with the NAT - solved

Started by May 14, 2006 12:43 PM
12 comments, last by MikeyO 18 years, 9 months ago
I am trying to implement it the way you said above.. here is the server logic (pseudocode):

while(true){    Packet incomingPacket = connection.receive();    string[] message = incomingPacket.data; //doesn't block because packets are in a queue.    if(message[0] == "0")//this means its a new user    {        userArrayList.Add(incomingPacket.endPoint);        SendToAll(userArrayList);    }}SendToAll(ArrayList users){    foreach(IPEndPoint ep in users)    {         connection.send("User has connected!", ep);    }}connection.send(string msg, IPEndPoint ep){    socket.SendTo(getBytes(msg), ep);}


The above works if: there is no NAT or if DMZ is enabled for my computer, or there is port forwarding/triggering.

I can still send packets to the server, but not receive them otherwise.
If the endpoint for the incoming client comes straight from the accepting call from the network, then this should work. If it doesn't, then it's likely a configuration or software problem with your firewall. Use Ethereal on the inside and outside of the firewall to make sure (or try another brand).

Your code looks a little dangerous, though: what if an existing player sends a message that contains just the text "0"? Your code would add a second entry for the same player (according to the pseudocode). Repeat as necessary for a nice DoS attack on your upstream bandwidth.
enum Bool { True, False, FileNotFound };
Advertisement
Heh, well... the actual program is a little bit different. If you send a '0' in front it will look like "1,0" when the server gets it, because 1 is the "Message" code (whereas 0 is the login code, which only sends when you hit the connect button). The code used is determined by the program, not the user.

The server/client are not the programs I am trying to develop, I am actually trying to make an easy to use network library for another program. The server is only 100 lines of code.

I have been pouring over documents on the internet and have not found any new information except one from http://www.mindcontrol.org/~hplus/nat-punch.html, where it says something about having a TTL of 2, but I have no idea what that means or how to implement it.
Well, as it turns out, I was attempting to experiment with someone who lived overseas and by altering the TTL (using .NET 2.0, which I was not initially using) to 45, so that the packet lasts a little longer, I was able to successfully punch through.

Thanks for your help.

This topic is closed to new replies.

Advertisement