开发者

Ruby TCP socket never gets replies

开发者 https://www.devze.com 2023-03-05 13:30 出处:网络
I use a TCP connection and send some data like this: begin session = "mysession" socket = TCPSocket.new(tcpaddress, port)

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
  开发者_JS百科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.


Perhaps you need to add CRLF to the command:

socket.write("HELO " + session + "\r\n")
0

精彩评论

暂无评论...
验证码 换一张
取 消