Page 1 of 1

Strange bandwidth problem, UDP and TCP

Posted: 10 Jan 2013, 23:30
by Eqric
Hi, i am running this code

Code: Select all

   // Update is called once per frame
   void FixedUpdate () {
   void UpdatePlayerPosition(){
      posX = transform.position.x;
      posY = transform.position.y;
      posZ = transform.position.z;
      SFSObject sendData = new SFSObject();
      sfs.Send(new ExtensionRequest("update_movement",sendData,null,true));

The problem is when i use TCP i send 5kb/s of data when i am running with my character and sending my position and rotation.
When i use UDP i send constant 50kb/s of data by doing the same thing.
How is this possible that i get this high bandwidth with UDP? I always thought it was lighter and faster then TCP and i still think 5kb/s is way to much.
What am i doing wrong?

Note: I am using the runtime statistics to measure the bandwidth.

Re: Strange bandwidth problem, UDP and TCP

Posted: 13 Jan 2013, 11:32
by ThomasLund
There should not be that big a difference between TCP and UDP. The binary packet that is created is the same for both, and the rest is up to the OS to handle. But if your setup by any chance changes to using bluebox (e.g. you forgot to enable UDP on server, so it uses HTTP instead) - THEN it would explain the size difference.

The amount of data per second is partly totally up to you to determine. Your example code is not real world code, so its a little hard to comment on the 5 kb/s.

You have most likely not changed the frequence of fixed updates. So that means its set to 0.02 = 50 times a second.

If you are sending 5 kb/s that then translates roughly into 100 bytes per send.

I dont think thats a lot, and there is definitely not room for improvement in the API code. If you are into the tiny details, then you can save some bytes in your code by renaming "user_id" into "ui" and "update_movement" to "u_m"

And reducing the send frequency is a given in production. You will not be able to run a system with so many updates. Look into reducing it down to e.g. 5-10 a second max and then have interpolation to handle all the frames in between updates.


Re: Strange bandwidth problem, UDP and TCP

Posted: 13 Jan 2013, 17:41
by Eqric
Hi Thomas! Thanks for the reply, it seems that it was a bug of some kind, the data sent using UDP changed from 50kb/s to 5kb/s when i upgraded the server to 2.5.0 from 2.0.1 :)

Re: Strange bandwidth problem, UDP and TCP

Posted: 13 Jan 2013, 17:50
by ThomasLund
Super duper :-)