Ruby TCPSocket 写入不起作用,但 puts 起作用了吗? [英] Ruby TCPSocket write doesn't work, but puts does?

查看:44
本文介绍了Ruby TCPSocket 写入不起作用,但 puts 起作用了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GServer 和 TCPSocket 开发 Ruby TCP 客户端/服务器应用程序.我遇到了一个我不明白的问题.我的 TCPSocket 客户端成功连接到我的 GServer,但我只能使用 puts 发送数据.调用 TCPSocket.send 或 TCPSocket.write 什么都不做.有什么我遗漏的魔法吗?

I'm working on a Ruby TCP client/server app using GServer and TCPSocket. I've run into a problem that I don't understand. My TCPSocket client successfully connects to my GServer, but I can only send data using puts. Calls to TCPSocket.send or TCPSocket.write do nothing. Is there some magic that I'm missing?

tcp_client = TCPSocket.new( ipaddr, port )
tcp_client.puts( 'Z' ) # -> GServer receives "Z\n"

但是如果我使用写或发送...

But if I use write or send...

tcp_client = TCPSocket.new( ipaddr, port )
tcp_client.write( 'Z' ) # -> nothing is received
tcp_client.send( 'Z' ) # -> nothing is received

感谢您的帮助

附加信息:

  1. 该行为在 Linux & 上是相同的.窗户.
  2. 写入后刷新套接字不会改变行为.

推荐答案

您确定问题不在服务器端吗?您是否正在使用某种方法来读取需要以\n"结尾的字符串或其他内容?

Are you sure the problem isn't on the server side? Are you using some method to read that expects a string or something ending in "\n"?

这篇关于Ruby TCPSocket 写入不起作用,但 puts 起作用了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆