Bill Kelly
2/24/2006 11:10:00 PM
From: "mitchell" <ffsnoopy@gmail.com>
>
> Unfortunately, I cannot use the send or recv commands because of
> buffering issues with TCP. It has to be gets/puts which is quite
> unfortunate, but I have no other simple workaround.
Hi, could you explain more about what you mean by buffereing issues?
I primarily use send/recv with TCP. It's not hard to make a
puts/gets wrapper around send/recv, for instance.
For ex: (untested, but similar to what i frequently have used)
def send_string(sock, str)
begin
while str.length > 0
if select(nil, [sock], nil, nil)
sent = sock.send(str, 0)
str = str[sent..-1]
end
end
rescue IOError, SystemCallError, SocketError
# ... set eof flag?
end
end
def puts(sock, str)
send_string(sock, "#{str}\n")
end
sock.fcntl(Fcntl::F_SETFL, sock.fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK) if defined? Fcntl::O_NONBLOCK
puts(sock, "hello")
Regards,
Bill