Ruby TCPSocket read_all
是否有一种方法可以像 read_all 一样工作,而不是使用 TCPSocket.read(no_of_bytes),只需 TCPSocket.read_all 即可。我首先通过 YAML::dump'ing 发送对象,然后发送它们,但我不知道如何获取它们的大小(以字节为单位)。预先感谢,嗯。哦,我对任何形式的网络编程都非常非常陌生,所以慢慢来吧!
Is there a method that can act like read_all, as in instead of using TCPSocket.read(no_of_bytes), one can simply TCPSocket.read_all. I am sending objects first by YAML::dump'ing them then sending them but I don't know a way to get their size in bytes. Thanks in advance, ell. Oh and I am very, very new to any form of network programming so go easy on me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑有这样的功能。然而!写它确实是最简单的部分。我必须让这种语言变得不可知,因为我已经很长时间没有编写任何 ruby 代码了,但在伪代码中它基本上就像这样
完成了。循环并接收,直到没有更多可用数据为止。这是最简单的任务之一:)
I doubt there is such a function. HOWEVER! Writing it really is the easiest part. I'm going to have to make this language agnostic, because it's a long time since I've written any ruby code, but in pseudocode it is basically like this
Done. Looping and receiving until there is no more data available. That's one of the easiest tasks :)
无法帮助您使用 Ruby,但对象序列化和网络的通常做法是首先发送长度,以便您知道要读取多少内容,或者使用预定义的分隔符来分隔消息。
Can't help you with Ruby, but the usual practice with object serialization and networking is to either send the length first, so you know how much to read, or use a pre-defined delimiter to separate messages.