Strange bandwidth problem, UDP and TCP

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Eqric
Posts: 4
Joined: 29 Aug 2012, 15:31

Strange bandwidth problem, UDP and TCP

Postby Eqric » 10 Jan 2013, 23:30

Hi, i am running this code

Code: Select all

   // Update is called once per frame
   void FixedUpdate () {
      sfs.ProcessEvents();
      
      UpdatePlayerPosition();
   }
   
   
   void UpdatePlayerPosition(){
      posX = transform.position.x;
      posY = transform.position.y;
      posZ = transform.position.z;
      SFSObject sendData = new SFSObject();
       
      
      sendData.PutDouble("x",posX);
      sendData.PutDouble("y",posY);
      sendData.PutDouble("z",posZ);
         //sendData.PutInt("user_id",1);
      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.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Re: Strange bandwidth problem, UDP and TCP

Postby ThomasLund » 13 Jan 2013, 11:32

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.

Best
Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Eqric
Posts: 4
Joined: 29 Aug 2012, 15:31

Re: Strange bandwidth problem, UDP and TCP

Postby Eqric » 13 Jan 2013, 17:41

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 :)
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Re: Strange bandwidth problem, UDP and TCP

Postby ThomasLund » 13 Jan 2013, 17:50

Super duper :-)
Full Control - maker of Unity/C# and Java SFS API and indie games

Follow on twitter: http://twitter.com/thomas_h_lund

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 22 guests