On Sun, Jul 20, 2003 at 07:57:13PM +0900, Pablo Lorenzzoni wrote:
> I also thought that would work (the construction is beautiful, isn't it?). The 
> problem is that gets wait for the Enter key to be hit, and I need to echo 
> every character instantaneously.

Well you can always do:

while a = server.read(1)
  client.write a
end

It's not especially efficient, but it will work.

You can't however do server.read(1024), say, because that will block until
1024 characters have been read. I think 1.8 has a feature which lets you
determine how many characters are available in the socket buffer to read
(but I can't remember what it is)

> | > Is there anyway to pipe two sockets? I want to forward everything that
> | > comes from socket1 to socket2 and vice-versa...

I guess you've discovered this already, but you can use threads to get the
bidirectional operation. This should work (untested):

Thread.new do
  while ch = socketa.read(1)
    socketb.write ch
  end
end
Thread.new do
  while ch = socketb.read(1)
    socketa.write ch
  end
end
... main thread continues at this point

Regards,

Brian.