[Red5] number of connections

Mondain mondain at gmail.com
Fri Jun 27 10:50:42 PDT 2008


There wont be any exceptions, he will most likely just get inaccurate counts
depending on which thread hits the -- or ++.

Paul

On Fri, Jun 27, 2008 at 9:48 AM, Walter Tak <walter at waltertak.com> wrote:

>  Wouldn't he see exceptions in the log when 2 treads try to access the
> non-thread-safe integer in his original example ?
>
> Or would java/red5 fail silent on the *num_connected--;* operation ?
>
> Regards,
> Walter
>
>
> ----- Original Message -----
> *From:* Mondain <mondain at gmail.com>
> *To:* red5 at osflash.org
> *Sent:* Friday, June 27, 2008 6:07 PM
> *Subject:* Re: [Red5] number of connections
>
> I would also like to add that the application adapter is multi-threaded so
> you must use a thread-safe counter. Java provides a set of Atomic objects
> that may be used for this sort of application. Below you will find your
> updated code:
>
> package org.red5.server;
>
> import java.util.concurrent.atomic.AtomicInteger;
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
>
> import org.red5.server.api.IConnection;
> import org.red5.server.adapter.ApplicationAdapter;
>
> public class Application extends ApplicationAdapter {
>
>     public static AtomicInteger num_connected = new AtomicInteger();
>
>     public boolean appStart() {
>        log.info( "Red5First.appStart" );
>        return true;
>     }
>
>     public void appStop() {
>        log.info( "Red5First.appStop" );
>     }
>
>     public boolean appConnect(IConnection conn, Object[] params) {
>        log.info( "Red5First.appConnect {}", conn.getClient().getId() );
>        num_connected.getAndIncrement();
>        boolean accept = (Boolean) params[0];
>        if ( !accept ) rejectClient( "you passed false..." );
>        return true;
>     }
>
>     public void appDisconnect(IConnection conn, Object[] params) {
>        num_connected.getAndDecrement();
>        log.info( "Red5First.appDisconnect {}", conn.getClient().getId() );
>     }
>
>     public int numberofusers() {
>        return num_connected.get();
>     }
>
> }
>
> Javadoc:
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/atomic/AtomicInteger.html
>
>
> Paul
>
> On Fri, Jun 27, 2008 at 8:49 AM, Walter Tak <walter at waltertak.com> wrote:
>
>> Which version of Red5 are you using
>> Where did you get it from (binary 0.6.3 , 0.7.0 + hotfix, SVN)
>> What browser are you using
>>
>> Tried firefox when you are using IE and vice versa ?
>>
>> Some versions IE have a problem ; appDisconnect does not fire even if you
>> close the TAB which holds the SWF.
>>
>> If you'd close the browser then the event fires (IE keeps the connection
>> open to R5 even when the SWF was unloaded).
>>
>> Also some specific version of Red5 had some problems with appDisconnect so
>> you might want to test with at least 2 different versions of R5, like the
>> old 0.6.3 and one of the latest trunk versions.
>>
>> You can run them all on 1 server ; just install Red5 in a different
>> directory, do not install the service on Windows and have Red5 listen on
>> different ports and have your client connect to the right port to test a
>> specific Red5-instance.
>>
>> Walter
>>
>>
>>
>> ----- Original Message -----
>> From: "Access-Dev ML" <ml at access-dev.com>
>> To: "red5" <red5 at osflash.org>
>> Sent: Friday, June 27, 2008 5:25 PM
>> Subject: [Red5] number of connections
>>
>>
>> > Hello,
>> >
>> > I m begging red5 dev and try to build an application that maintain a
>> count
>> > of the numbers of simultaneous
>> > connected users.
>> >
>> > Maybe there is classes for that but i try the simple way and it s not
>> > working, the number of users keeping growing even if
>> > i disconnect flash client.
>> >
>> > Maybe red5 is unable to find the the flash client has closed the window
>> >
>> > here is the code:
>> >
>> > package org.red5.server;
>> >
>> > import org.apache.commons.logging.Log;
>> > import org.apache.commons.logging.LogFactory;
>> >
>> > import org.red5.server.api.IConnection;
>> > import org.red5.server.adapter.ApplicationAdapter;
>> >
>> > public class Application extends ApplicationAdapter
>> > {
>> >    private static final Log log = LogFactory.getLog( Application.class
>> );
>> >    public int num_connected     = 0;
>> >
>> >    public boolean appStart ( )
>> >    {
>> >        log.info( "Red5First.appStart" );
>> >        num_connected = 0;
>> >        return true;
>> >    }
>> >
>> >
>> >    public void appStop ( )
>> >    {
>> >        log.info( "Red5First.appStop" );
>> >    }
>> >
>> >    public boolean appConnect( IConnection conn , Object[] params )
>> >    {
>> >        log.info( "Red5First.appConnect " + conn.getClient().getId() );
>> >        num_connected++;
>> >        boolean accept = (Boolean)params[0];
>> >        if ( !accept ) rejectClient( "you passed false..." );
>> >        return true;
>> >    }
>> >
>> >    public void appDisconnect( IConnection conn , Object[] params )
>> >    {
>> >    num_connected--;
>> >        log.info( "Red5First.appDisconnect " + conn.getClient().getId()
>> );
>> >    }
>> >
>> >    public int numberofusers() {
>> >    return num_connected;
>> >
>> >    }
>> >
>> >
>> > on the flash side :
>> >
>> > package
>> > {
>> >
>> >    import flash.net.NetConnection;
>> >    import flash.net.ObjectEncoding;
>> > import flash.net.Responder;
>> >    import flash.events.NetStatusEvent;
>> >    import flash.display.Sprite;
>> >
>> >    public class Red5FirstClient extends Sprite
>> >    {
>> >        public var nc:NetConnection;
>> >        public function Red5FirstClient()
>> >        {
>> >            this.nc = new NetConnection( );
>> > this.nc.client = this;
>> >            this.nc.objectEncoding = ObjectEncoding.AMF0;
>> >            this.nc.addEventListener( NetStatusEvent.NET_STATUS ,
>> > netStatus );
>> >            this.nc.connect( "rtmp://localhost/firstapp" , true );
>> >
>> >        }
>> >
>> > public function numberofusers():void {
>> >
>> > trace("this nc " + this.nc);
>> > this.nc.call("numberofusers",new Responder(this.callbackusers));
>> >
>> >
>> > }
>> >
>> > public function callbackusers(result:int) {
>> > trace("num users " + result);
>> > }
>> >
>> >        private function netStatus ( event:NetStatusEvent ):void
>> >        {
>> >            trace( event.info.code );
>> >            if ( event.info.code == "NetConnection.Connect.Rejected" ){
>> >                trace( event.info.application );
>> >            }
>> >        } // end netStatus
>> >
>> >
>> >    } // end Red5FirstClient
>> >
>> > } // end package
>> > }
>> >
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > Red5 mailing list
>> > Red5 at osflash.org
>> > http://osflash.org/mailman/listinfo/red5_osflash.org
>> >
>> >
>> >
>> > --
>> > No virus found in this incoming message.
>> > Checked by AVG.
>> > Version: 7.5.524 / Virus Database: 270.4.1/1521 - Release Date:
>> 6/26/2008
>> > 11:20 AM
>> >
>> >
>>
>>
>> --
>> I am using the free version of SPAMfighter for private users.
>> It has removed 352 spam emails to date.
>> Paying users do not have this message in their emails.
>> Get the free SPAMfighter here: http://www.spamfighter.com/len
>>
>>
>>
>> _______________________________________________
>> Red5 mailing list
>> Red5 at osflash.org
>> http://osflash.org/mailman/listinfo/red5_osflash.org
>>
>
>
>
> --
> It is difficult to free fools from the chains they revere. - Voltaire
>
> ------------------------------
>
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
>
> ------------------------------
>
> No virus found in this incoming message.
> Checked by AVG.
> Version: 7.5.524 / Virus Database: 270.4.1/1521 - Release Date: 6/26/2008
> 11:20 AM
>
>
> ------------------------------
> I am using the free version of SPAMfighter for private users.
> It has removed 352 spam emails to date.
> Paying users do not have this message in their emails.
> Try SPAMfighter <http://www.spamfighter.com/len> for free now!
>
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
>
>


-- 
It is difficult to free fools from the chains they revere. - Voltaire
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/red5_osflash.org/attachments/20080627/e47cdedf/attachment.html 


More information about the Red5 mailing list