From: Brian Candler Date: 2009-03-09T23:08:34+09:00 Subject: Re: Question about GServe and IO Michael Furmaniuk wrote: > This worked great! I can keep my connection up and running and thin. > Still not sure what the delay is in sending a command and getting one > back, it seems to be off by one - probably something with the > communication I don't understand yet. If you use "telnet 127.0.0.1 3472" and type in commands by hand, does it work as expected? That would suggest the problem is in your client side program rather than the server. Maybe your server is sending one extra blank line or something which the client isn't expecting, so it's always reading one line behind. However, 'readpartial' is a very dubious thing to be doing at the client side, since it may only read 1 byte when the server has more data to send. You need to frame your protocol in such a way that it's unambiguous where the end of a message is. Possible ways to do this: - make each response exactly one line (client just does "s.gets") - the SMTP/POP3 body way: have multiline responses ended by a special terminating character This is a multiline message . (note that any body line which starts with a '.' has an extra '.' prepended, to avoid ambiguity) - the SMTP response way: flag each line which is not the last 250-This is a multi-line response 250-which the client keeps reading 250-until it gets to a line which doesn't 250 have a dash after the number - the SMTP/HTTP chunking way: output a length (decimal or hex), followed by that number of bytes. len = Integer(s.gets.chomp) body = s.read(len) - the DRb binary way: send a 4-byte length in network order, followed by that number of bytes. After you have eliminated readpartial from your program, if you still have a problem, please make a trimmed down client/server pair and post them in their entirety, so the problem can be reproduced. HTH, Brian. -- Posted via http://www.ruby-forum.com/.