Ruby TCP 套接字永远不会得到回复
我使用 TCP 连接并发送一些数据,如下所示:
begin
session = "mysession"
socket = TCPSocket.new(tcpaddress, port)
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
puts "sending to socket HELO " + session
socket.write ('HELO ' + session)
puts socket.read
socket.close
rescue Exception => myException
puts "Exception rescued : #{myException}"
end
套接字永远不会收到回复,但是 telnet 会收到回复:
$ telnet some_ip port
Trying some_ip...
Connected to some_ip
Escape character is '^]'.
HELO mysession
OK
正如您所看到的,远程服务器按预期回复“OK”。怎么了?
PS:我也使用过 put 和 send 方法。
I use a TCP connection and send some data like this:
begin
session = "mysession"
socket = TCPSocket.new(tcpaddress, port)
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
puts "sending to socket HELO " + session
socket.write ('HELO ' + session)
puts socket.read
socket.close
rescue Exception => myException
puts "Exception rescued : #{myException}"
end
The socket never gets a reply, however, telnet does:
$ telnet some_ip port
Trying some_ip...
Connected to some_ip
Escape character is '^]'.
HELO mysession
OK
As you can see the remote server replies "OK" as expected. What's wrong?
PS: I have used puts and send methods also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您需要在命令中添加 CRLF:
Perhaps you need to add CRLF to the command: