Game Networking Issues

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Game Networking Issues

Post by nathanf534 »

I am testing the multi-player function of my game (character position updating, and world updates) and sometimes the character position doesn't update. I believe this might be because the client is behind a firewall, but I would like to get another opinion on this.

The game uses port 3279 for TCP (world updates) and port 3280 UDP (character position updates). I am behind a wireless router and have forwarded those ports to my computer.

If I run 2 clients on the same computer as the server (using the external ip address) everything works fine.

If I run 1 client on my computer, and a friend of mine (in a different location) runs a client is when I have issues.
The friends computer doesn't receive my character position updates (UDP). I think this might be because a firewall could be blocking that, although I have had the friend run a test where the the client sends a message to the server, and the server responds, and that works fine. I tried it with another person, and I had the same results.

So if the firewall is blocking the UDP connection, how could I get it so it isn't blocked? (The TCP isnt blocked I guess because its a connection based protocol)


Thanks for any help, please ask questions if you don't understand my problem.
while(signatureEmpty){cout<<wittyComment();}
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Maybe it's losing packets? I thought UDP did not make sure packets make it to their destination.
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

It might be losing packets, but it doesn't receive any of the UDP packets for character updating, even if it received some it would work.
while(signatureEmpty){cout<<wittyComment();}
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Is port forwarding set up on his router also? UDP doesn't have connections, so there is no client/server architecture there, everyone is both the client and server so you'd need to open ports at both ends.

I guess you ought to use UPNP to enable NAT to client machines from their routers, but I'm not sure exactly how Windows deals with that.

Maybe this will help:

http://www.codeproject.com/KB/IP/PortForward.aspx
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
pippy3
Posts: 155
Joined: Tue Dec 15, 2009 7:32 am

Post by pippy3 »

I've had the same problem.


Some routers won't accept a UDP packets from a 3rd party source. You have to have both the client and the server send packets to get the router accept them. It's more complicated than that, some won't accept any unless port forwarding has been enabled.

My recommendation is use only TCP to start with. Switching to UDP is a major headache that can be very time consuming.
pandoragami
Posts: 226
Joined: Wed Jan 26, 2011 5:37 pm
Contact:

Post by pandoragami »

I had router issues too with irrnetlite and I just connected my computer directly to my cable modem. I'm using zonealarm which is really a hassle since it works so well, I have to click the little check box and allow my connection every single time I recompile my program.

Im not even sure if I use UDP or TCP.
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

So I was just thinking, if you type in "ping www.google.com" in cmd (or the equivalent for any non-Windows computer) your computer will send a UDP packet to www.google.com, which will receive it, and send you a UDP packet in response. As far as I can tell, this always works even if I have port forwarding disabled. So how is my computer able to receive those packets without having port-forwarding, but a client can't accept UDP packets from my server? It seems like they are doing almost the same thing to me.
while(signatureEmpty){cout<<wittyComment();}
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

your computer sent the initial request therefore the router see's it as you leaving the network. What a firewall does is prevent access from outside the network. So a firewall is configured to block all incoming messages unless they are to a forwarded port. if it is it will send those messages to the ip address and port specified. So if the server tries to establish the connection then it will be blocked but if the client connects to the server then the router sees it as an outbound stream basically. Some routers do block outbound streams as well as inbound but I believe their default setting are block all inbound, allow all outbound.

This is why some network games require you to open the firewall on the router while most well programmed games don't need it and just need to be able to get to the port on your computer's firewall. Look at Black ops for example, all connections are started from the client making it so you don't need to open any ports on the router. In reality the only time you need to open a port on the router is when you have a server running that people outside your network connect to.

EDIT: I haven't played with udp sockets but I am pretty sure if you have the client connect to the server first then the server should be able to respond on that connection without issue. Just make sure the server isn't trying to start the connection.
olivehehe_03
Posts: 157
Joined: Tue Mar 20, 2007 8:30 am

Post by olivehehe_03 »

If you're receiving packets from another computer (typically if you are the server) and you are behind a router you need to forward the ports that you're using. What this does is when your router receives a packet on that port, port forwarding directs that packet to the appropriate IP address on your internal network.

If you're not sure if the packets are getting from client to server, I can think of two ways to check. You could write yourself a simple test program that will send a stream of UDP packets to an IP address and port and another program that will listen on that port and print a message if it receives it. Something like this should help identify if your packets are getting through. You could also use a program like Wireshark to check for network activity to see what packets are being received.
Tell me what you cherish most. Give me the pleasure of taking it away.
Post Reply