Receive AS3 objects in Java through sockets

Hi.

How do i receive flash objects in java?

I’m trying to create a multiplayer game, i’ve chosen sockets to handle this and Java as the server. So far i made myself a client/server already. And it works when sending as3 objects. but, not the way i want it!

I made a class in AS3 and in Java that represents the object to be sent.

AS3 Class ‘Package’


 package com.myapp.pck {
     
     import flash.net.registerClassAlias;
     import flash.display.Sprite;
     import flash.utils.IDataInput;
     import flash.utils.IDataOutput;
     import flash.utils.IExternalizable;
     
     public class Package implements IExternalizable {
 
         public var cont:String = "test";
         
         //constructor
         public function Package(){
             registerClassAlias( "Package", Package );
         }
         
        //getsetters here
 
         
         public function readExternal(input:IDataInput):void
         {
             cont = input.readObject() as String;
         }
     
         public function writeExternal(output:IDataOutput):void
         {
             output.writeObject(cont);     
         }
     }
     
 }
 

And the Java Class ‘Package’


 
 package myserver;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 
 
 public class Package implements Externalizable {
 
     String cont;
 
 
      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
     {
         cont = (String)in.readObject();
         System.out.println(cont);
     }
 
     public void writeExternal(ObjectOutput out) throws IOException
     {
         out.writeObject(cont);
     }
 }
 
 

With flash i simple send the object (Note that this isn’t the complete code)


//init blabla
socket:Socket = new Socket();
p:Package = new Package();

//send
p.writeExternal( socket );
socket.writeUTFBytes("
");

And java receives it with


 //java
 out = new PrintWriter(socket.getOutputStream()); 
 in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

String line = ois.readLine();
while(line != null){
                //get input here
}

I receive the Object (serialized string actually) just fine and i can send it right back so flash can reconstruct an object out of it again. but here is the problem:

I want to access the object in java, edit it, and send it back, but if i even edit the raw serialized string, flash will not read it anymore.
so my goal is to ‘import’ the flash Object structure so i can access every variable in Java.

I tried using

oos = new ObjectOutputStream(socket.getOutputStream());
ois = new ObjectInputStream(socket.getInputStream());

instead of the PrintWriter or BufferedReaded but no luck there, Because the ObjectInputStream can’t read the serialized string and returns with a “Invalid stream header”. Even when i pass the string right to the Package class method:

Package p = new Package();
p.readExternal(ois);

I tried google alot, but i dont seem to find anyone that shares my problem.

Thank you.

I wasnt sure in which forum to post, because it has a bit of everything heh. Sorry if this is the wrong one"