简体   繁体   English

解决套接字tcp中创建的数据包时间的方法

[英]A way to resolve the time of packet created in socket tcp

I am using socket TCP in C#. 我在C#中使用套接字TCP。

Here is some code: 这是一些代码:

System.Net.Sockets.Socket clientSocket; System.Net.Sockets.Socket clientSocket;

... ...

clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

...
clientSocket.Receive( ...)

The clientSocket object receive data - There is a created packet on the server side, which decide when sending it. clientSocket对象接收数据-服务器端有一个已创建的数据包,该数据包决定何时发送数据包。

Is there any way to retrieve the date+time the packet was sent and when it was created? 有什么方法可以检索数据包发送的日期和时间以及创建时间?

Also, is there any way to retrieve the date+time when using protocol such as REST? 另外,在使用诸如REST之类的协议时,有什么方法可以检索日期和时间?

Need some sample code, please. 请提供一些示例代码。

Thanks :) 谢谢 :)

It depends on the protocol running over TCP that will determine whether you will be able to determine such date time information. 取决于TCP上运行的协议,该协议将确定您是否能够确定此类日期时间信息。 You will need to interpret the block of bytes returned by Receive() as per the protocol you are interested in. 您将需要根据您感兴趣的协议解释Receive()返回的字节块。

For example code see this tutorial: http://www.codeguru.com/csharp/csharp/cs_network/sockets/article.php/c8781/Asynchronous-Socket-Programming-in-C-Part-II.htm 有关示例代码,请参见本教程: http : //www.codeguru.com/csharp/csharp/cs_network/sockets/article.php/c8781/Asynchronous-Socket-Programming-in-C-Part-II.htm

REST isnt a protocol. REST不是协议。 RESTful apis don't typically contain a date+time each message was sent unless someone has designed that into their API. RESTful api通常不包含每条消息发送的日期和时间,除非有人在其API中进行了设计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM