   Lidgren Network Connection Error
  I have been using the Lidgren Networking Library to set up a online XNA game over the last while, but I've noticed that the connections seem to be very intermittent. The strange thing that I can't figure out is that *sometimes* the connection works perfectly, yet other times they simply refuse to establish a connection. I've got all the debug messages printing to the window so I think I've a good idea of what appears to be going on:Here is what happens when everything is fine:1. The client sends out a DiscoverKnownPeer to my Server's IP and listening Port.2. The server responds, telling it the IP and Port to use. (When it works, the port is always 14242)3. The client connects using this information, no problem.But here is what seems to happen *most* of the time:1. The client sends out a DiscoverKnownPeer to my Server's IP and listening Port.2. The server responds, telling it the IP and Port to use. (This is not 14242)3. The client attempts to connect using the given IP and Port.4. The server responds to this connection request using a different Port to the one it used in the DiscoveryResponse.3. The client gets this response, but refuses to accept it due to it not matching the port it was expecting.4. The client sends a connection request back to the Server, asking it again to connect.5. The server responds again.6. The client still refuses to accept the server as it isn't responding on the port it wants.My server keeps telling me that it is using the same port (14242 in this case), but by checking the responses in my client I can see that it is using a different port that seems to keep changing with each new connection, so my client will not accept it. I am fairly new to networking, so I'm trying to take it simply and create a fairly basic chat program before attempting anything as complex as a proper game, so the solution to this might be rather obvious, but any help would be appreciated! My problem appears to be due to the ports, but I'm not even sure why it sometimes responds using the same port, and other times doesn't. Thanks for any input!I've included four images in the links below, showing the messages displayed by the client and server both when they're working and when they are not.Working ServerWorking ClientNot Connecting ServerNot Connecting Client
1. The client sends out a DiscoverKnownPeer to my Server's IP and listening Port.2. The server responds, telling it the IP and Port to use. (When it works, the port is always 14242)3. The client connects using this information, no problem.First, you probably want to use WireShark on the client and server computers to debug this. Chances are, you'll figure it out on your own if you do this!Second, is there a router/modem/firewall between the client and the server computer? Specifically, if NAT is involved, and it sometimes re-uses the port used on the inside of the NAT, but most of the time doesn't, then you would see the symptoms you describe. The FAQ has more information about NAT and what to do about it. Easiest: set up port forwarding.   