Author Topic: How to see stats like incoming and outgoing bytes?  (Read 1912 times)

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
How to see stats like incoming and outgoing bytes?
« on: October 21, 2016, 03:01:57 AM »
Is it possible to display in TNet my incoming and outgoing bytes and messages(rfc's)?
To see how much bandwith are used on Client and Server side?

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: How to see stats like incoming and outgoing bytes?
« Reply #1 on: October 21, 2016, 07:03:41 PM »
Add a public int BytesReceived to the top of TNGameClient.cs, then in the ProcessPacket function add: BytesReceived += buffer.size;
Now, in TNManager add a float BPSTimer = 0f, and an int BytesPerSecond. In TNManager's Update function, add this AFTER the call to mClient.ProcessPackets():
  1. BPSTimer += Time.deltaTime;
  2. if (BPSTimer >= 1f)
  3. {
  4.         BPSTimer = 0f;
  5.         BytesPerSecond = mClient.BytesReceived;
  6.         mClient.BytesReceived = 0;
  7. }
  8.  

That'll get you incoming bytes per second on the client. Outgoing bytes could follow the same process, except you'd be looking into TNTcpProtocol::OnSend and TNUdpProtocol::OnSend functions. Stats on the server would, again, follow the same process, but you'd look into TNGameServer.cs::ThreadFunction for incoming bytes. Outgoing bytes on the server could use the same OnSend functions as the client. Timing bytes/sec on the standalone server is slightly more involved as you don't have Unity calling the Update function every frame, but for the sake of brevity I'll let you figure it out :P

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to see stats like incoming and outgoing bytes?
« Reply #2 on: October 21, 2016, 08:57:32 PM »
When I was actively tracking this with Windward, I just did it via the windows task manager. You can navigate to the details of a specific app and see exactly how much bandwidth it's using.