0
votes

I'm writing a Flex application.

The server side application is Java application that is on top of Red5 1.0. that connection is made throught RTMPE protcol. (the results are the same with RTMP or RTMPE).

I have am able to properly connect to the server and enter and leave rooms, but I am not able to connect to a shared object in a room. using a non-persistent shared object.

I create a shared object in a room in the server side using the following code:

private void createSharedObject (IScope scope, String soName, boolean persistent) {
    ISharedObjectService service= (ISharedObjectService) ScopeUtils
            .getScopeService(scope,
                    ISharedObjectService.class,
                    false);
    service.createSharedObject(scope, soName, persistent);
}

private ISharedObject getSharedObject(IScope scope, String soName,boolean persistent) {
    ISharedObjectService service = (ISharedObjectService) ScopeUtils
            .getScopeService(scope,
                    ISharedObjectService.class,
                    false);
    return service.getSharedObject(scope, soName,persistent);
}

   public ISharedObject getRoomSharedObject() {
        final String soName = "room_" + this._scope.getName();

            log.debug("application found. creating shared object");
                log.debug("shared object: {} not found for scope: {}. creating one",new Object[]{soName,this._scope.getContextPath()});
            createSharedObject(this._scope, soName, XpoConstants.persistentSharedObjects);
            ISharedObject so = getSharedObject(this._scope,soName, XpoConstants.persistentSharedObjects);
            so.clear();

            return so;

    }      

then the user enters the proper room I get the connction, and invoke a function at his end and provide the Shared Object name so he will know what to to connect to using the following code:

    IConnection conn = Red5.getConnectionLocal();
    IServiceCapableConnection sc = (IServiceCapableConnection) conn;
    sc.invoke("<function name>", new Object[]{this._so.getName(),...});

now in the client side, I use the following code in the flex application to get the remote shared object:

var roomSharedObject:SharedObject = SharedObject.getRemote(soName,   SharedUtils.getNetConnection().uri, Finals.persistentSharedObject);

roomSharedObject.addEventListener(NetStatusEvent.NET_STATUS, this._parse);

roomSharedObject.addEventListener(SyncEvent.SYNC,this._parse2);
roomSharedObject.connect(SharedUtils.getNetConnection());

...

    private function _parse(e:NetStatusEvent):void {
        trace("NETSTATUSEVENT");
        trace("########## EVENT INFO CODE: " + e.info.code);
    }

    private function _parse2(e:SyncEvent):void {
        trace("SYNCEVENT");

    }

the only message that I get from red5 is the following:

[INFO] [pool-8-thread-12] org.red5.server.so.SharedObject - Deleting shared object room_3963 because all clients disconnected and it is no longer acquired.

I would guess that NetStatusEvent should be triggered would some kind of error message but I get no trace messages at all! and the only thing that I get from red5 is that the shared object is deleted which means that that client tried to connect for a sec and disconnected.

I tired to google, tired the red5 google group. i'm lost! any information regarding the issue would be greatly appreciated.

thank you!

update

ok I created a smaller client and server..

at the server, the appConnect function just return true.

the client is a flex 4.6 client with the following code:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" creationComplete="init()"
minHeight="600">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[
    import mx.controls.Alert;

    private var nc:NetConnection = new NetConnection();

    private function init():void {

        nc.proxyType = "best";
        nc.objectEncoding = ObjectEncoding.AMF0;
        nc.addEventListener (NetStatusEvent.NET_STATUS,checkConnect);                    
        nc.connect("rtmpe://127.0.0.1/ufktest");

    }

    private function checkConnect (event:NetStatusEvent):void
    {
        switch (event.info['code']) {
            case 'NetConnection.Connect.Success':
            {   
                _red5Connected();
                trace('connected succesfully');
                break;
            }
            case 'NetConnection.Connect.Closed':
            {   
                _red5Disconnected();
                trace('connection closed');
                break;
            }
            case 'NetConnection.Connect.Rejected':
            {
                _red5Disconnected();
                trace('connection rejected' );
                break;
            }
            case 'NetConnection.Connect.Failed':
            {
                _red5Disconnected();
                trace('connection failed');
                break;
            }
            case 'NetConnection.Connect.AppShutDown':
            {
                trace('app shut down');
                _red5Disconnected();
                break;
            }
            default:
            {
                trace("unknown netconenction status: " + event.info['code']);                   
                break;
            }               
        }

    }

        private function _red5Connected():void {
            trace("red5 connection was successful");
            var roomSharedObject:SharedObject = SharedObject.getRemote("moshe",nc.uri,false);
            roomSharedObject.addEventListener(NetStatusEvent.NET_STATUS, _parse);
            roomSharedObject.addEventListener(SyncEvent.SYNC,_parse2);
            roomSharedObject.connect(nc);


        }
    private function _parse(e:NetStatusEvent):void {
        trace("NETSTATUSEVENT");
        trace("########## EVENT INFO CODE: " + e.info.code);
    }

    private function _parse2(e:SyncEvent):void {
        trace("SYNCEVENT");

    }

        private static function _red5Disconnected():void {
            trace("disconnected from red5");
            Alert.show("could not connect to server, please try again later");
        }


    ]]>
</fx:Script>

and still when I run the client application it connects to the server and give me the following error:

[INFO] [pool-8-thread-15] org.red5.server.so.SharedObject - Deleting shared object moshe because all clients disconnected and it is no longer acquired.
2

2 Answers

1
votes

Any more logs? However your log suggests that the shared object was created successfully on the server.Try using acquire() method on creation of the shared object inside roomStart() or wherever you are creating it(roomStart() should be the right place though). Server by default would destroy any shared object if no client is connected.

0
votes

This seems like an overly complex way to do this. If you use the Flex method SharedObject::getRemote all of this will be taken care of for you. If the object exists the client will get a copy. If it doesn't exist the object will be created. So first person in 'the room' creates the object and anyone that shows up later will get a copy.