3

I'm fairly new to networking and lidgren has made it much easier for me to begin adding multiplayer capability to my XNA PC game. I've been testing across the network setting up my laptop right next to me and it has been working great. The problem is I sent a copy of my game to a friend in the Netherlands and she cannot connect to me. I have it set up to where one person is the host and other people are clients who connect to that host.

The host sets up the server as follows:

 Config = new NetPeerConfiguration("game");
 Config.Port = 14242;
 Config.EnableUPnP = true;
 Config.MaximumConnections = 3;
 Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
 Server = new NetServer(Config);
 Server.Start();
 Server.UPnP.ForwardPort(14242, "Forlorn Forest");

Here's the exception ForwardPort throws as it fails and gives "Bad Request": enter image description here

And two web exceptions that are thrown: enter image description here enter image description here

It says something about the connection being closed by the remote host and unable to read data from the transport connection in the exception details: enter image description here

Any thoughts as to what might be going on here? UPnP is enabled on my router. I've taken a look at network traffic with WireShark and I can see it display malformed packets though I didn't mess with any of the Lidgren code so I'm not sure why it would.

Ted
  • 277
  • 1
  • 3
  • 14
  • I've added a break point in "internal void ExtractServiceUrl(string resp)" and it gets to and sets the status to Available and then it goes to the method again a second time and that's when the exception occurs. – Ted Jun 27 '14 at 23:24
  • It looked like enabling UPnP had to set some stuff up so I decided to take out the ForwardPort request from there and put it in the host's update area and wait for UPnP to be set to available before I sent in the ForwardPort request and now I see it show up in the upnp portmap table on the router though it does still give the two exceptions and now after a minute or two it gives "The thread '' (0x149c) has exited with code 0 (0x0)". – Ted Jun 29 '14 at 03:31
  • After some looking into it, it could just be a thread created by Lidgren that concluded doing it's job. And maybe it's fine that I can't get rid of the exceptions... I see the port added to the UPnP portmap table so that's what's important I guess. I'll test again when I can. – Ted Jun 29 '14 at 03:48
  • I tested it with a friend who lives a few hours away and he was able to connect to me so perhaps it'll be alright to ignore those exceptions if it's working at least... – Ted Jun 29 '14 at 21:33

1 Answers1

3

The UPnP protocol specification has unfortunately not been properly implemented on a huge number of the home routers out there. The effect of this is that all UPnP frameworks (Even the Intel spec framework) will fail to properly communicate UPnP with some local routers.

You should find that not all of your friends routers will successfully open the ports you request. The best you can do is make sure your code has no failure scenarios and uncaught exceptions relating to the UPnP framework you're using and that you have it well documented how users who fail UPnP can manually setup port forwards for your game.

S.Richmond
  • 11,412
  • 6
  • 39
  • 57
  • Thanks for the explanation and advice. That's understandable. Many games seem to just leave it up to the players to be required to forward the port themselves. I'll try to do as you suggested and keep in mind that some people will be required to do it manually. – Ted Jul 01 '14 at 08:13