[Red5] IScope.disconnect() and Red5.getConnectionLocal()

Walter Tak walter at waltertak.com
Thu Aug 6 17:19:24 PDT 2009


I agree it's confusing.

It wouldn't be bad if the current IConnection would be added as a third 
parameter to method leave() (or to replace IClient by IConnection since it's 
easy to do a IConnection.getClient() lookup)

Probably not many people made applications where multiple -connections- to 
the same scope are being used or made a workaround.

Paul what do you think about that ?

W.

----- Original Message ----- 
From: "Zayzon, Gergely" <gergoe at nexver.hu>
To: <red5 at osflash.org>
Sent: Friday, 07 August 2009 01:54
Subject: Re: [Red5] IScope.disconnect() and Red5.getConnectionLocal()


> The actual problem is that you can not tell which particular connection 
> leaves the scope, it's just a guesswork. Usually one client indeed only 
> has one connection, and usually one client is connected to one scope only, 
> and usually one client is not connected to the same scope more than once. 
> But I hate to leave code behind which might go wrong one day and then I 
> need to spend the time I never have to find out what goes wrong because of 
> such a leftbehind. That's my actual problem.
>
> By the way, MultiThreadedApplicationAdapter.leave() mentions that it 
> directly calls appLeave and roomLeave (so it can be guessed what 
> Red5.getConnectionLocal() will do), but IScope.disconnect() does not 
> mention that it directly calls MultiThreadedApplicationAdapter.leave(). 
> Could have dig that up from the source although.
>
> Anyway, I thought this to be something which is obliviously wrong, but 
> seems I was on the wrong track.
>
>
> Regards,
> Gergely Zayzon
>
>
> Walter Tak wrote:
>> What is the actual problem ?
>>
>> Since roomLeave (method [leave] in (MultiThreaded)ApplicationAdapter) 
>> receives the 2 parameters [scope] and [client] you can figure out which 
>> connection
>> we are dealing with (client.getConnections() which often returns just one 
>> connection unless you have been connected more than once to the same 
>> scope at a time).
>>
>> API docs of [leave]:
>>
>> http://api.red5.nl/org/red5/server/adapter/ApplicationAdapter.html#leave(org.red5.server.api.IClient,%20org.red5.server.api.IScope) - 
>> ---- Original Message ----- From: "Zayzon, Gergely" <gergoe at nexver.hu>
>> To: <red5 at osflash.org>
>> Sent: Friday, 07 August 2009 00:28
>> Subject: Re: [Red5] IScope.disconnect() and Red5.getConnectionLocal()
>>
>>
>>> In my opinion calling Red5.getConnectionLocal() from 
>>> Application.roomLeave() should always return the IConnection which is 
>>> leaving the scope, not the one which is one way or another, but 
>>> triggered the leave. Why would you want to access the connectionA if 
>>> connectionB is leaving?
>>>
>>> Yes, it is certainly by design, by the design and definition of 
>>> Red5.getConnectionLocal(), but if you put this into an 'event handler' 
>>> of a connection (sort of), then I get surprised to see a different 
>>> connection than the one which triggered the event handler (and now I see 
>>> the one which called a method, which triggered an event handler).
>>>
>>> If the IConnection would be passed with Application.roomLeave(), then it 
>>> would have been trivial that I do not tamper with 
>>> Red5.getConnectionLocal(), but that's not the case (and actually I'm not 
>>> sure that roomLeave() is meant for connection or clients, but since one 
>>> client can have more connections, but one connection can not have more 
>>> clients, i think that in any case, it should belong to connections).
>>>
>>> So the design of Red5.getConnectionLocal() is perfect imho, but if you 
>>> combine that with Application.roomLeave(), then you might get weird 
>>> results. Don't know if that's something which has an easy fix, but it 
>>> should be mentioned at least (somewhere).
>>>
>>> By the way, would it not be a lot better to have two 
>>> Application.roomLeave(), one for connections and one for clients? Then 
>>> the implementor could choose which one is suitable for his/her purpose?
>>>
>>>
>>> Regards,
>>> Gergely Zayzon
>>>
>>>
>>> Walter Tak wrote:
>>>> Well isn't that by design ?
>>>>
>>>> Red5.getConnectionLocal() always returns the handle or reference to the 
>>>> current connection that is executing the code.
>>>>
>>>> In this case you are 'the local connection' whever method you call , 
>>>> Red5.getConnectionLocal() will always return your own connection.
>>>>
>>>> Since you are disconnecting everybody BUT yourself your boolean isWrong 
>>>> (which would tell if the connection bing dropped is the current 
>>>> connection) will always be true.
>>>>
>>>> Remove the extra if inside disconnectEverybody() [ if (conn != 
>>>> connection) { }] and then you -should- see one [isCorrect] boolean with 
>>>> a value of [true].
>>>>
>>>>
>>>> ----- Original Message ----- From: "Zayzon, Gergely" <gergoe at nexver.hu>
>>>> To: <red5 at osflash.org>
>>>> Sent: Thursday, 06 August 2009 19:42
>>>> Subject: [Red5] IScope.disconnect() and Red5.getConnectionLocal()
>>>>
>>>>
>>>>> When disconnecting an IConnection using scope.disconnect(conn), then 
>>>>> invoking Red5.getConnectionLocal() from the Application.roomLeave() 
>>>>> method returns the IConnection from the connection which triggered the 
>>>>> IScope.disconnect(), not the one which is leaving the scope.
>>>>>
>>>>> Consider the following *fictitious* code:
>>>>>
>>>>> public class Application extends MultiThreadedApplicationAdapter {
>>>>>
>>>>>  public void disconnectEverybody() {
>>>>>   IConnection conn = Red5.getConnectionLocal();
>>>>>   IScope scope = conn.getScope();
>>>>>   for (Set<IConnection> connectionSet : scope.getConnections())
>>>>>    for (IConnection connection : connectionSet)
>>>>>     if (conn != connection) {
>>>>>      scope.setAttribute('callee', conn);
>>>>>      scope.disconnect(connection);
>>>>>     }
>>>>>  }
>>>>>
>>>>>  public void roomLeave(IClient client, IScope room) {
>>>>>   IConnection conn = Red5.getConnectionLocal();
>>>>>   Boolean isWrong = (conn==room.getAttribute('callee'));
>>>>>   Boolean isCorrect = (conn!=room.getAttribute('callee'));
>>>>>  }
>>>>>
>>>>> }
>>>>>
>>>>> ...in which for me the roomLeave() method will always have isWrong 
>>>>> true and isCorrect false. disconnectEverybody is called from 
>>>>> ActionScript - of course.
>>>>>
>>>>>
>>>>> Regards,
>>>>> -- 
>>>>> Gergely Zayzon
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> 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
>>>
>>> _______________________________________________
>>> 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
>
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
> 




More information about the Red5 mailing list