Skip

Help me chat!
October 8, 2009 3:55 PM   Subscribe

Asking for a friend: Java/action script 3 question - Remote Shared Object Question with Red5 Flash Server and Flash AS3

Hello,

I am trying to create a simple chat client using the red5 media server, but I seem to be having a slight hiccup. I am creating a shared object on the server side, and it seems to be creating it successfully. However, when I make changes to the object via the client (type a message), the SYNC event fires, but the content within the shared object remains empty. I suspect I am doing something wrong on the java end, any advice?

Console Results:

Success!

Server Message: clear

Server Message: [object Object]

Local message: asdf

Server Message: change

Server Message: [object Object]

Local message: fdsa

Server Message: change

Server Message: [object Object]

Local message: fewa

Server Message: change

Server Message: [object Object]


Server Side:

public class Application extends ApplicationAdapter {

private IScope appScope;

// private static final Log log = LogFactory.getLog( Application.class );

/** {@inheritDoc} */

@Override

public boolean connect(IConnection conn, IScope scope, Object[] params) {


appScope = scope;

createSharedObject(appScope, "generalChat", false); // Creates general chat shared object


return true;

}

/** {@inheritDoc} */

@Override

public void disconnect(IConnection conn, IScope scope) {

super.disconnect(conn, scope);

}

public void updateChat(Object[] params)

{

ISharedObject so = getSharedObject(appScope, "generalChat"); // Declares and stores general chat data in general chat shared object

so.setAttribute("point", params[0]);

}

Client Side:

public class SOConnect extends MovieClip

{

// Variables

var nc:NetConnection = null;

var so:SharedObject;

public function SOConnect():void

{

}

public function connect():void

{

// Create a NetConnection and connect to red5

nc = new NetConnection();

nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

nc.connect("rtmp://localhost/chatTest");

// Create a StoredObject for general chat

so = SharedObject.getRemote("generalChat", nc.uri, false);

so.connect(nc);

so.addEventListener(SyncEvent.SYNC, receiveChat)

}

public function sendChat(msg:String)

{

trace ("Local message: " + msg);

nc.call("updateChat", null, msg)

}


public function receiveChat(e:SyncEvent):void

{

for (var i in e.changeList)

{

trace ("Server Message: " + e.changeList[i].code)

trace ("Server Message: " + e.changeList[i])

}

}

// Given result, determine successful connection

private function netStatusHandler(e:NetStatusEvent):void

{

if (e.info.code == "NetConnection.Connect.Success")

{

trace("Success!");

}

else

{

trace("Failure!\n");

trace(e.info.code);

}

}

}
posted by yoyoceramic to Computers & Internet (2 answers total)
 
createSharedObject(appScope, "generalChat", false);

according to the documentation for this method, the final parameter should be true, for persistent. could that be it?

(not a red5 pro).

docs
posted by klanawa at 4:12 PM on October 8, 2009


Stack Overflow is usually better for this sort of thing.
posted by Who_Am_I at 7:21 AM on October 9, 2009


« Older I am looking for recommendatio...   |  How to dismantle an old Boiler... Newer »
This thread is closed to new comments.


Post