Ruby Sockets 查找消息的发送和接收时间
ruby 中的套接字类是否有一个预定义函数,可以让我记录发送和接收消息的时间?
目前我正在发送或接收消息,然后立即记录时间。虽然这有效,但我想知道是否有人知道更好的方法?
这是我目前的做法。这是基于我必须编写的 ClientTCP 类。服务器以类似的方式布局。
def send_mess
@n.times do
@client.print(@message)
@sent_time_arr << (Time.now.to_f)
sleep(1/@freq)
end
@client.close
return @sent_time_arr
end
您能提供的任何帮助将不胜感激
Is there a predefined function for the socket classes in ruby that will allow me to record the time messages are sent and received?
At the moment I am sending or receiveing the message, and then recording the time immediately afterwards. While this is working I was wondering if anyone knew a better method?
Here is how i do it at the moment. This is based off a ClientTCP class i had to write. The servers are laid out in a similar manner.
def send_mess
@n.times do
@client.print(@message)
@sent_time_arr << (Time.now.to_f)
sleep(1/@freq)
end
@client.close
return @sent_time_arr
end
Any help you could provide would be greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,标准套接字库无法做到这一点。您可以尝试重写套接字类上的
read()
和write()
方法,但您现在所做的似乎也有效。I'm sorry, but there is no way to do this with the standard socket library. You could try to override the
read()
andwrite()
methods on the socket class, but what you are doing now seems to be working as well.