From: "Berger, Daniel" Date: 2002-08-15T00:51:43+09:00 Subject: RE: Problems with Marshal > -----Original Message----- > From: Hugh Sasse Staff Elec Eng [mailto:hgs@dmu.ac.uk] > > On Wed, 14 Aug 2002, Daniel Berger wrote: > > > "incompatible marshal file format (can't be read) (TypeError)" > > How are you sending and receiving the data? Ok, I've narrowed it down partially to a newline issue with Marshal. Here are a sample client and server to demonstrate. Just start the server in one terminal and the client in another. Uncomment the appropriate lines to view the different behavior. More comments at end... # SAMPLE SERVER require 'socket' a = ["one","two","three"] # -> This gets wonky results #a = ["one","two","three\n"] # -> This works #a.push("\n") # -> This causes "marshal data too short" x = Marshal.dump(a) tcpServer = TCPServer.open('localhost',8877) $tcpServer = tcpServer addr = tcpServer.addr addr.shift # remove "AF_INET" #puts "Server is on port: " + addr.shift.to_s while true Thread.start(tcpServer.accept) do |s| puts "Accepted connection: #{s}" r = s.gets puts "Got #{r} from client" s.puts(x) s.close end end # SAMPLE CLIENT require 'socket' s = TCPSocket.open('localhost',8877) s.puts("hello") # send whatever v = s.gets a = Marshal.load(v) a.each do |x| puts x end s.close # more comments The question I have, then, is how do I make sure that the marshalled object is properly newline terminated? Regards, Dan