As you can see the remote server replies “OK” as expected. What’s wrong?
If the server is expecting ‘line oriented input’, then the server will
continue trying to read from the socket until it encounters a newline,
i.e. you need to end the data you send with a newline.
When you use sockets, both sides have to communicate with an agreed upon
protocol. If one side deviates from that protocol, then you are going
to end up with deadlock, where both sides are waiting for the other side
to do something.
That may or may not make a difference to a particular program.
One way to avoid the newline conversion is to use the actual ascii code
for a newline instead of “\n”:
“\r\n” in octal:
“\015\012”
“\r\n” in hex:
“\x0D\x0A”
To avoid having to put those ugly escape sequences in your string, the
perl socket library has the constant $CRLF, which can be used at the end
of strings when correct reading of the data requires that line endings
be marked with exactly one “\r” and one “\n”. However, I don’t think
ruby copied that feature from perl.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.