From: Farrel Lifson Date: 2002-04-29T01:36:04+09:00 Subject: Inconsistent network behaviour Hi all, I'm a Ruby newbie when it comes to network programming so while writing a little example to teach myself it I came across this rather inconsistent behaviour. Firstly here are my two scripts. One is a server which listens on a port and the other a client which sends it simple messages. #client.rb require "socket" session = TCPSocket.new("localhost",5179) session.send("INVITE sip:you@bar.com SIP/2.0\n",0) session.send("From: me@foo.com\n",0) session.send("To: you@bar.com\n",0) session.send("\r\n",0) session.close #server.rb require "socket" def parse_header(socket) data = "" connec = Hash.new while (data != "\r\n") data = socket.recv(1000) print "Data read: ",data property,value = data.split(/: /) connec[property]=value end connec end server = TCPServer.new("localhost",5179) while (session=server.accept) connection = Hash.new data = session.recv(100) if (data.split)[0] == "INVITE" connection = parse_header(session) end end When I run the server on my Linux box (Mandrake 8.1, Kernel 2.4.8, Ruby 1.6.4) I get the desired output: Data read: me@foo.com Data read: you@bar.com When I run it on a FreeBSD box (FreeBSD 4.4,Ruby 1.6.3) the output is: Data read: me@foo.com To: you@bar.com The program reads the two lines (sent using two seperate send method calls) in with one recv, as well as the final "\r\n" which causes it to then go into an infinite loop (printing out Data read: Data read: Data read: ...) as it keeps on reading in from the socket even though it is closed on the client side. This is a simple exercise so I'm sure there's a solution, just that I can't find anything in the pickaxe book or online docs. Any ideas what the problem is and why the behaviour is different on Linux and FreeBSD? Thanks in advance, Farrel Lifson -- |DNA Research Group mailto:flifson@cs.uct.ac.za |Dept. of Computer Science http://www.cs.uct.ac.za/~flifson |University of Cape Town +27-21-650-3127