PDA

View Full Version : Red5 appDisconnect problem solution


Antonos
01-17-2008, 09:59 AM
There are a lot of tutorials in the web about red5. When I was trying to build my first application for red5 server I was using following tutorial
http://www.actionscript.org/resources/articles/615/1/Getting-started-with-red5-server/Page1.html
When I compile app in eclipse, restart red5 server and was trying to connect to this application via my flash client, I detect from the red5.log that appConnect method worked correctly but when I closed flash client which was connected to red5 server, nothing happened. Seems that appDisconnect was not triggered.

I found solution in Red5 mailing list
http://www.mail-archive.com/red5@osflash.org/msg10694.html

appDisconnect method should override super class method. I change code from

public void appDisconnect( IConnection conn , Object[] params )
{
log.info( "Red5First.appDisconnect " + conn.getClient().getId() );
}


to

/** Override super class method */
@Override
public void appDisconnect( IConnection conn )
{
log.info( "Red5First.appDisconnect " + conn.getClient().getId() );
super.appDisconnect(conn);
}


and it was working properly

Same problems can appear working with roomStart, appStart and appStop methods

I hope this information will help someone.

webreake
01-31-2008, 04:14 AM
yea thats a good tip , i also suggest to use try/catch blocks in every method while debugging to know where exceptions are from.

i have been using my apps without calling super.appDisconnect(conn); i wonder if that makes my server to have ghost connections so far no errors :p

Antonos
01-31-2008, 07:57 AM
yea thats a good tip , i also suggest to use try/catch blocks in every method while debugging to know where exceptions are from.

i have been using my apps without calling super.appDisconnect(conn); i wonder if that makes my server to have ghost connections so far no errors :p

for now you have no errors, but some garbage will stay on your server
maybe problems will appear in future when garbage will be too much
better to call super class method appDisconnect to clean all garbage

webreake
01-31-2008, 07:55 PM
yes i just added that line to my code i also use "scheduleGhostConnectionsCleanup"

i have a doubt maybe you can help me,
to send an object to flash like this :
var params = {uniqueId:somevar, roomUserList:somevar2}
in java i use something like this :
Object [] params = new Object[1];
ObjectMap map = new ObjectMap();
map.put("uniqueId" , somevar);
mapa.put("roomUserList", somevar2 );
params[0] = mapa;

is there a better way to do it ?

Antonos
01-31-2008, 09:49 PM
is there a better way to do it ?

I belive it is

I have same problem now,
I need to organize chat in each room
I am thinking in this way:
e.g uri is rtmp://localhost/app/room
need to send some unique user_ID to red5 when client connects
in appConnect( IConnection conn , Object[] params )
we can get room scope (conn.getScope()), red5 client id (conn.getClient().getId()) and our user_ID (from params)
in roomStart(IScope room)
we can get room scope which we have in appConnect

need to think how to organize users list in each room with shared objects

I will let you know when I will invent it

maybe someone else have some ideas ???

webreake
01-31-2008, 11:37 PM
i just did a chat like ff0000.com for one of my clients and there i had to organize users in rooms,

I recommend you to use org.red5.server.api.Red5 and org.red5.server.api.ScopeUtils those objects make a lot easier the use of scopes and connections.

my structure is :
->rootScope (Iscope)
------>room1 (IScope)
----------- ->userList (ISharedObject)

So when a client connects i have a function wich connects this user to a room and notify the client, when the client knows it is connected to a room it tries to connect to the sharedObject userList.

To notify the client about its new Scope connection so it can call the shared object with "rtmp://server/myRed5app/myroom/userList" when i receive the event onConnect in red5 i call ServiceUtils.invokeOnConnection (conn, "flash_method", params);
(get the conn using org.red5.server.api.Red5 )

Hope been clear , im still learning to speak/write english :)