3 Replies - 780 Views - Last Post: 13 April 2013 - 02:11 PM Rate Topic: -----

#1 DorZ11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 11-April 13

how to check the elapsed time with tcp client using serialization inC#

Posted 13 April 2013 - 01:46 PM

I need to know how to check properly the elapsed time of sending messages between two clients and 1 server.

I tried to put in my object that I transfer the the exact time in milliseconds with the next function:

class exactTime {
  public static double ConvertSecondsToMilliseconds() {
    return TimeSpan.FromSeconds(DateTime.Now.Second).TotalMilliseconds;
  }
  public static double ConvertMinutesToMilliseconds() {
    return TimeSpan.FromMinutes(DateTime.Now.Minute).TotalMilliseconds;
  }
  public static double ConvertHoursToMilliseconds() {
    return TimeSpan.FromHours(DateTime.Now.Hour).TotalMilliseconds;
  }
  public static double ExactTime() {
    double exacatTime = DateTime.Now.Millisecond + ConvertHoursToMilliseconds() + 
       ConvertMinutesToMilliseconds() + ConvertSecondsToMilliseconds();
    return exacatTime;
  }
}


than when I recieve the message I use the same function than I subtracting what I got with the time that I got in the object that I got but the output isnt good, like that:

double remainderTime = exactTime.ExactTime() - tcpObject.exactTime;


I return the result to client 1 and I print all in the server and look the output:
Posted Image

1 is client num1
2 is client num2 that recieve and send the results..


is it make any sence that most of the messages recieved in 0 ms?

btw its on the same machine running..and connect to the localhost

Is This A Good Question/Topic? 0
  • +

Replies To: how to check the elapsed time with tcp client using serialization inC#

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1020
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: how to check the elapsed time with tcp client using serialization inC#

Posted 13 April 2013 - 01:56 PM

Well, a millisecond is 1/1000th of a second. If you have a local network with 48Mbps (slowest device on my current network) you can transmit 48kbps in 1 millisecond. That's a text string about 4800 characters long (if you include framing bits, etc.) How long is the data you are sending?
Was This Post Helpful? 1
  • +
  • -

#3 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5922
  • View blog
  • Posts: 20,251
  • Joined: 05-May 12

Re: how to check the elapsed time with tcp client using serialization inC#

Posted 13 April 2013 - 02:06 PM

Dude, what are you doing with all those extra ConvertXXXToMilliseconds? You could have simply done:
DateTime startTime;
DateTime endTime;
double elapsedTimeInMilliseconds = (endTime - startTime).ToTotalMilliseconds;



So your endTime time could be initialized to DateTime.Now when you get the message, and in your message, you can also set your startTime to DateTime.Now at send time.

Of course you also have to factor in that two different machines may not have their clocks exactly synchronized. So you'll need to do some handshaking between the two to figure out the time delta between the two machines.

Be warned that when sending on your loopback circuit on localhost, it tends to be very very fast. You may need to resort to using the High Performance Counters to get the time delta.

This post has been edited by Skydiver: 13 April 2013 - 02:08 PM

Was This Post Helpful? 1
  • +
  • -

#4 DorZ11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 11-April 13

Re: how to check the elapsed time with tcp client using serialization inC#

Posted 13 April 2013 - 02:11 PM

View PostMomerath, on 13 April 2013 - 01:56 PM, said:

Well, a millisecond is 1/1000th of a second. If you have a local network with 48Mbps (slowest device on my current network) you can transmit 48kbps in 1 millisecond. That's a text string about 4800 characters long (if you include framing bits, etc.) How long is the data you are sending?

wow u right! I sent 100BS..
when I tried to send 40000kbs the numbers changed but I get memory exception after few messages.. how can I transfer huge messages between the clients?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1