Go Back   kirupaForum > Flash > ActionScript 3.0

Reply
 
Thread Tools Display Modes
Old 11-28-2009, 06:17 PM   #1
OmniNL
Registered User
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'
PHP Code:
 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'
PHP Code:
 
 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 inthrows IOExceptionClassNotFoundException
     
{
         
cont = (String)in.readObject();
         
System.out.println(cont);
     }
 
     public 
void writeExternal(ObjectOutput outthrows IOException
     
{
         
out.writeObject(cont);
     }
 } 
With flash i simple send the object (Note that this isn't the complete code)

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

//send
p.writeExternalsocket );
socket.writeUTFBytes("\n"); 
And java receives it with

PHP Code:
 //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

PHP Code:
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:

PHP Code:
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"

Last edited by OmniNL; 11-28-2009 at 06:25 PM..
OmniNL is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-29-2009, 10:01 AM   #2
OmniNL
Registered User
Remove this one please, i made one in the Java forum.

Last edited by OmniNL; 11-29-2009 at 01:10 PM..
OmniNL is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:57 AM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com