TCPSocket#send and TCPSocket#write are functionally same.
But TCPSocket#puts appends "\n" to the output string.
HTH,
Yes, thank you for the example. I have been using write, but I did not
see many examples using this method while lots of examples use send and
puts. Should I use send rather than write? Will write be deprecated
someday?
TCPSocket#send and TCPSocket#write are functionally same.
I think #write will block until all the data is sent, whereas #send
may return immediately, having sent only part of the data.
With #send you may need a loop like this:
def send_string(sock, str)
begin
while str.length > 0
sent = sock.send(str, 0)
str = str[sent..-1]
end
rescue IOError, SocketError, SystemCallError
# eof = true
end
end
Ruby's standard socket library is very similar to BSD socket interface:
send(2) and write(2).
I guess ruby's socket library will support both send and write methods
consistently along with POSIX as such other cases.
···
On 4/13/06, brad tilley <rtilley@vt.edu> wrote:
Gyoung-Yoon Noh wrote:
> TCPSocket#send and TCPSocket#write are functionally same.
> But TCPSocket#puts appends "\n" to the output string.
>
> HTH,
Yes, thank you for the example. I have been using write, but I did not
see many examples using this method while lots of examples use send and
puts. Should I use send rather than write? Will write be deprecated
someday?