[Red5] Connecting to a different scope issue; org.red5.server.BaseConnection.connect ( IScope scope, Object[] params )
Andres Alva
andresa88 at gmail.com
Fri Feb 15 14:38:41 PST 2008
Hi!
Phew. And I thought I was the only with this problem. Boy am I glad to hear
from you.
So that sounds like a good temporary fix! So now the problems comes down to
figuring out how to recompile red5 with the code changes. How do you do it?
Also, we should post this on the dev mailing list don't you think? I'll go
ahead and do that.
Andres
On Feb 15, 2008 12:37 AM, thomas wajs <thomas at quedesjeux.com> wrote:
> Man, i had the EXACTLY same troubles, issues and reflexion.
>
> I was leading to write myself a mail today to explain the whole thing
> you just talk about. So I totally agree with you, there's a problem with
> this damn disconnect function.
>
> If you check BaseConnection.connect, you'll see :
> if (scope.connect(this, params)) {
> if (oldScope != null) {
> oldScope.disconnect(this);
> }
> Disconnect happen AFTER connect.
>
> First when you reconnect, the *disconnect() functions take IConnection
> as parameter, and when you call conn.getScope() you have a wrong scope
> (the new one instead of the old one).
>
> And as you said, there's a wrong behaviour with the (un)registration of
> the connections into the "common" parent scopes of the two scopes.
> Because the disconnection come after the connection, you'll be
> disconnected from the first levels of common scoping. Thus, when the
> client will really disconnect, *disconnect functions won't be correctly
> called on these common scope.
>
> I rewrited this function o workaround, but it's not very clever as this
> can lead to a total failure, and being connected to nowhere :
>
> public boolean connect(IScope newScope, Object[] params) {
> final Scope oldScope = scope;
> if (oldScope != null) {
> oldScope.disconnect(this);
> }
> scope = (Scope) newScope;
> if (scope.connect(this, params)) {
> return true;
> } else {
> scope = oldScope;
> scope.connect(this,params);
> return false;
> }
> }
>
> It corrected all my problems for now. I'd suggest to rearrange this
> function so that disconnect happen with the correct scope, and do not
> interfer with the common parent scope of the new scope.
>
>
> Le jeudi 14 février 2008 à 16:25 -0800, Andres Alva a écrit :
> > Hello,
> >
> > The past 2 weeks or so I've been developing a Red5 app in which users
> > would be able to switch scopes. Originally I was resorting to having
> > the Flash client establish a new connection to the server every time I
> > wanted to switch scopes. For example:
> >
> > AS3:
> >
> > //connect to the lobby scope
> > _nc.connect("rtmp://localhost/Game/golf/lobby");
> >
> > //then to join a different scope (room) under the "golf" scope I'd
> > establish a new connection, the
> > //original connection would be closed
> > _nc.connect("rtmp://localhost/Game/golf/room1");
> >
> >
> > But then I asked myself if this was efficient. Now I don't have much
> > of a background in server development, but I figured that establishing
> > a new socket connection is a costly operation and one that should be
> > minimized as much as possible. So I went ahead and instead chose to do
> > all the scope switching on the server. That is, have the connection
> > objects join different scopes via the BaseConnection.connect( )
> > method. So I went ahead and modified my app to use this method hoping
> > that everything would go smoothly, but I ran into an issue.
> > Apparently, I get disconnected from the parent scopes after I've
> > connected to the new scope which is not supposed to happen. Now first
> > take a look at the BaseConnection.connect( ) method code (found in the
> > Red5 source code):
> >
> > org.red5.server.BaseConnection.connect
> >
> > public boolean connect(IScope newScope, Object[ ] params) {
> > final Scope oldScope = scope;
> > scope = (Scope) newScope;
> > if ( scope.connect ( this, params ) ) {
> > if (oldScope != null) {
> > oldScope.disconnect(this); <-------- Notice this line,
> > which I believe is the source of my problems
> > }
> > return true;
> > } else {
> > scope = oldScope;
> > return false;
> > }
> > }
> >
> > }
> >
> > Now suppose I have a client connected to the following scope tree:
> >
> > Game -> golf -> lobby
> > (uri: rtmp://localhost/Game/golf/lobby)
> >
> > Then say I created another scope called "room1" under the golf scope.
> > Then in order to connect the connection object to this new scope,
> > "room1" I would have something like this in my main application
> > handler class:
> >
> >
> > Game.java
> >
> > public boolean joinRoom ( ) {
> > IConnection conn = Red5.getConnectionLocal();
> > IScope lobbyScope = conn.getScope( );
> >
> > //create the new scope "room1" under the Game -> golf scope
> > //here lobbyScope.getParent( ) is a reference to the "golf" scope
> > lobbyScope.getParent().createChildScope ( "room1" );
> >
> > //finally connect the connection object to the new scope
> > conn.connect ( lobbyScope.getParent( ).getScope("room1") );
> >
> > }
> >
> > What I get, after looking at the log output, is that the conn object
> > successfully connects to the new scope, "room1", BUT then afterwards I
> > get notified that the same connection object is then disconnected from
> > the "Game" and "golf" scope. So I'm left with a connection connected
> > to the "room1" scope, but not to its parent scopes which is obviously
> > not supposed to happen. Now I believe the reason this is happening is
> > because of the line of code I marked in the BaseConnection.connect( )
> > method above:
> >
> > oldScope.disconnect(this);
> >
> > Because the oldScope and the newScope (lobby and room1 respectively)
> > share the same parent scopes,
> >
> > Game -> golf -> lobby oldScope
> > Game -> golf -> room1 newScope
> >
> > oldScope.disconnect(this) will remove the connection object (this)
> > which is now connected to "room1" from its parent scopes "Game" and
> > "golf". ALSO, the connection object will remain connected to the
> > oldScope, "lobby". oldScope.disconnect(this) fails to disconnect the
> > connection object from "lobby". I have no idea how to fix this or if
> > it is even an issue, maybe I'm doing it all wrong, which is why I'm
> > here seeking any help. Thank you!
> >
> > Maybe this could be clarified by a Red5 developer? I'd appreciate it
> > alot. I really don't want to have to resort to creating new
> > connections just to switch scopes.
> > _______________________________________________
> > Red5 mailing list
> > Red5 at osflash.org
> > http://osflash.org/mailman/listinfo/red5_osflash.org
>
>
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/red5_osflash.org/attachments/20080215/a0da80e3/attachment-0001.html
More information about the Red5
mailing list