From: Robert Klemme Date: 2009-06-17T16:14:30+09:00 Subject: Re: Ruby Socket to Java Socket 2008/9/25 Jim Morris : > Serge Savoie wrote: >> >> Ok, I have experiment a lot and found that : >> >> When the Java Server use : >>    in = requestSocket.getInputStream(); >> >> It works... I can read what the Ruby socket is sending... >> >> But the real Java server that I have to talk with use : >> >>    in = new ObjectInputStream( new BufferedInputStream( >> requestSocket.getInputStream() ) ); >> >> And in this case I get : >> >> java.io.StreamCorruptedException: invalid stream header >>  at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:753) >>  at java.io.ObjectInputStream.(ObjectInputStream.java:268) >>  at project1.SergeServer1.main(SergeServer1.java:44) > > The Java server is reading a Marshalled Java object, Usually that will only > be used for two Java processes talking to each other. Exactly. Java and Ruby do *not* share a common serialization format. You must take measures to explicitly handle serialization formats - or more generally define the protocol you want to use on that connection. > If you are sending very simple Java Objects you could format it in Ruby and > transmit it, but it would be messy. You will have to read the Sun documents > on Java serialized object formats, look at the ObjectInputStream Javadoc for > references to the required formats. > > Try using JRuby instead and serialize the Java object in Java. There are more alternatives: - use one of the many XML serialization packages around, - generally use a SOAP API, - use YAML on both ends. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/