Author Topic: UDP not working properly  (Read 5776 times)

unmaker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
UDP not working properly
« on: December 09, 2014, 09:38:07 PM »
I have a strange problem with TNet where my router doesn't seem to send or receive UDP packets.

This is really frustrating, I spent a week trying to get this to work, doing a lot of testing and etc... Ultimately, it came down to my router not being able to use UDP the way it is implemented in TNet.

I am making a somewhat 2.5D platform-er racing game where using UDP for quick position update is important, but can't get the damn SendQuickly to work. I have tried using only TCP, but even with noDelay = true; The movement is still jittery.

So, I started out with a new set up and decided to test the example3 scene that came with the package. After running two instances on my machine(connecting via my external IP) and using a program to track packets sent/received on my network. It showed that only TCP is being sent/received and no UDP at all. 

However, It shows canUseUDP  true on both clients and I have pretty much completely turned off my firewall. I am using the latest version of TNet.. the server message states 3 UPnP ports openedsuccessfully.. I have tried turning on and off mutlicasting - no luck there. I tried assigning my interface manually
  1. UdpProtocol.defaultNetworkInterface = new IPAddress(new byte[]{192, 168,0, 100});
no luck there...

I thought maybe there is a problem with looping back to my external IP, so I signed up for a free amazon ec2 micro... tried running the server there.. with all ports opened.. firewall off andddd still... Only TCP packets being sent with example 3, no UDP.

But here is the strange thing... after attempting many times of running server on amazon ec2 and connecting to it... there few times that it DID send UDP packets instead of TCP :0 As a result, the boxes wee moving much more smoother. But once closing the client connection and then reconnecting.. it goes back to TCP...

Finally I tried disconnecting my cable from my router and plugged it directly into the modem anddd.. what you know.. it worked! - it sends/receives UDP packets... Even when connecting to my server on amazon, it was using UDP - the boxes were moving much more smoother.

Furthermore, I tried running the server on my machine again WITH router, but this time connecting both clients through localhost(127.0.0.1) and yeppp that worked as well...

So, the problem seems to be that my router(DIR-857) is not compatible with how UDP is implemented in TNet.  This is a fairly expensive router and I have had no problem with other games online such as Quake.. CS:GO, HON, dota, and many other games...

I seen other people that have reported the same issue. I am really hoping there is a way to get UDP work because there is really not much point in releasing a game if it only works on some routers. I really like TNet and do not want to switch to another network as I did with photon.

If anyone has any suggestions, or perhaps that can point me to a direction would be much appreciated - Thank you!


 











« Last Edit: December 09, 2014, 09:52:22 PM by unmaker »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UDP not working properly
« Reply #1 on: December 11, 2014, 09:23:58 AM »
Ha. I remember that router... I had so many issues with it for the 3 months I had it before it finally just up and died on me... I got an Asus router after that and it fixed all the issues I had.

I don't know what its problem with UDP is (and I suggest looking at its settings), but TNet should automatically fall back to TCP if UDP is not available. The fact that it doesn't sounds like an issue I need to look into.

unmaker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UDP not working properly
« Reply #2 on: December 11, 2014, 10:20:46 AM »
Hmmm..... the router seem to have problems only with TNet.. works fine with everything else.. Could it be that TNet uses UPnp?

Anyways.. after more debugging this is what I found:

for example: When connecting through external IP to myself.

-Client opens port 12345(an example) for listening.
-RequestSetUDP sets the correct port 12345 on the server
-Client sends UDP packet to server on port 5128
-Server receives the UDP packet from the Client, but from some different port, example: 1037
-Server sends UDP packet to client on port 12345.
-Client never receives the UDP packet; hence, UDP falls back to TCP...

Now, When connecting through localhost to server.

-Client opens port 12345(an example) for listening.
-RequestSetUDP sets the correct port 12345 on the server
-Client sends UDP packet to server on port 5128
-Server receives the UDP packet from the Client on same 12345 port
-Server sends UDP packet to client on port 12345.
-Client receives the packet from server on 127.0.0.1, port 5128.. UDP works completely fine

Edit: When disconnecting router and connecting directly through the modem i get the exact same result as when connecting through localhost. The server sends UDP to client on the same port that was set by RequestSetUDP.


Why is the port different when UDP is received from client through external IP??? ..what gives? - Is it suppose to be different??

« Last Edit: December 11, 2014, 11:19:10 AM by unmaker »

unmaker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UDP not working properly
« Reply #3 on: December 11, 2014, 12:56:21 PM »
Ahhhhh finally got it to work!

I opened the port using UPnP instead of TNManager.StartUDP();

Now all packets being sent on the same port between client and server and UDP working so far so good!

But my quesiton is.. how come this wasn't done by you? is there a problem opening ports using UPnP on client side?? Will it cause any thing strange?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UDP not working properly
« Reply #4 on: December 13, 2014, 12:08:19 AM »
When you do StartUDP(), you are specifying a port you wish to use for receiving purposes. If you intend for data to come from outside your LAN, then you need to open up this port using UPnP so that the router knows to let traffic through. It's the same as using TCP. UDP is frequently used just for LAN server discovery -- so opening up port by default wouldn't be a good idea.

TNet automatically opens up a port via UPnP only if you actually host a server via TNServerInstance.Start.