locked
How to get the high precision timestamp when a packet reached over a tcp connection? RRS feed

  • Question

  • In windows xp socket development , I want to get the timestamp when a packet reached over tcp connection . This time precision must be lower than 1 ms.

    I know that I can get this timestamp from the packet grasped by Winpcap. But I want to find another way to get it in application layer.

    How can I do this?

    Thanks.
    • Moved by Jesse Jiang Thursday, December 30, 2010 3:07 AM (From:Visual C++ General)
    Wednesday, December 8, 2010 2:50 AM

Answers

  • tjuzhangrui wrote:

    tjuzhangrui wrote:

    In windows xp socket development , I want to get the timestamp when  a packet reached over tcp connection . This time precision
    must be lower than 1 ms.

    I know that I can get this timestamp from the packet grasped by  Winpcap. But I want to find another way to get it in application
    layer.

    By the time the data reaches application layer, there are no packets  anymore, just a stream of bytes constituting the payload.
    If you want to see packets, you must work at the transport level, or  lower.

    Anyway can I get the high precesion timestamp of the stream when I  recevie it?

    What's "timestamp of the stream"? Individual bytes constituting this  stream may have arrived with different packets at different times,  possibly more than once, not necessarily in the order they are reported  to you.

    Because I got a multithread application, the way as below can not get  the expected results.

    In any case, by the time you get the data, it may have been sitting in  Winsock buffers for a while. Windows is not a realtime operating system.

    If you don't mind me asking - what are you trying to achieve? What's the  goal of the exercise?


    Igor Tandetnik

    • Marked as answer by tjuzhangrui Thursday, December 30, 2010 9:37 AM
    Wednesday, December 8, 2010 5:20 AM

All replies

  • tjuzhangrui wrote:

    In windows xp socket development , I want to get the timestamp when a  packet reached over tcp connection . This time precision
    must be lower than 1 ms.

    I know that I can get this timestamp from the packet grasped by  Winpcap. But I want to find another way to get it in application
    layer.

    By the time the data reaches application layer, there are no packets  anymore, just a stream of bytes constituting the payload. If you want to  see packets, you must work at the transport level, or lower.


    Igor Tandetnik

    Wednesday, December 8, 2010 3:01 AM
  • tjuzhangrui wrote:

    In windows xp socket development , I want to get the timestamp when a  packet reached over tcp connection . This time precision
    must be lower than 1 ms.

    I know that I can get this timestamp from the packet grasped by  Winpcap. But I want to find another way to get it in application
    layer.

    By the time the data reaches application layer, there are no packets  anymore, just a stream of bytes constituting the payload. If you want to  see packets, you must work at the transport level, or lower.


    Igor Tandetnik


    Thanks!

    Anyway can I get the high precesion timestamp of the stream when I recevie it?

    Because I got a multithread application, the way as below can not get the  expected results.

     

     

         WSAWaitForMultipleEvents(.., hEvent, ...);
    
         QueryPerformanceCounter(&timestamp);
    

     

     

    Wednesday, December 8, 2010 3:26 AM
  • tjuzhangrui wrote:

    tjuzhangrui wrote:

    In windows xp socket development , I want to get the timestamp when  a packet reached over tcp connection . This time precision
    must be lower than 1 ms.

    I know that I can get this timestamp from the packet grasped by  Winpcap. But I want to find another way to get it in application
    layer.

    By the time the data reaches application layer, there are no packets  anymore, just a stream of bytes constituting the payload.
    If you want to see packets, you must work at the transport level, or  lower.

    Anyway can I get the high precesion timestamp of the stream when I  recevie it?

    What's "timestamp of the stream"? Individual bytes constituting this  stream may have arrived with different packets at different times,  possibly more than once, not necessarily in the order they are reported  to you.

    Because I got a multithread application, the way as below can not get  the expected results.

    In any case, by the time you get the data, it may have been sitting in  Winsock buffers for a while. Windows is not a realtime operating system.

    If you don't mind me asking - what are you trying to achieve? What's the  goal of the exercise?


    Igor Tandetnik

    • Marked as answer by tjuzhangrui Thursday, December 30, 2010 9:37 AM
    Wednesday, December 8, 2010 5:20 AM
  • If you don't mind me asking - what are you trying to achieve? What's the  goal of the exercise?


    Igor Tandetnik

    I want to make a test to see how much time will it take from sending a request till receiving the server's response.

     

    What's "timestamp of the stream"? Individual bytes constituting this  stream may have arrived with different packets at different times,  possibly more than once, not necessarily in the order they are reported  to you.

    In any case, by the time you get the data, it may have been sitting in  Winsock buffers for a while. Windows is not a realtime operating system.


    Igor Tandetnik

    I think I have some misunderstanding about the network transfer.

    Now I will consider it in other way.

    Thanks for you help.
    Wednesday, December 8, 2010 6:44 AM
  • It may not have the precision you want but, you can do something like this:

    DWORD startTime = GetTickCount();
    // send data to server
    // recieve data from server
    DWORD endTime = GetTickCount();
    
    DWORD ellapsedTime = endTime-startTime;
    printf("The response time is %d ms", ellapsedTime);
    

    Wednesday, December 8, 2010 5:17 PM