[Red5] Creating chatromm. How to send to any clients ?

Patrice FERLET metal3d at gmail.com
Tue Feb 19 01:29:00 PST 2008


No, in fact I really have a problem:
public boolean appJoin(IClient client, IScope app){
        System.out.println("App joined by");
        System.out.println(client.getAttribute("name"));

        //for every connections i have on this scope
        Iterator<IConnection> connections =  app.getConnections();
        while(connections.hasNext()){
            System.out.println("into appjoin...");
            IConnection conn = connections.next();
            IServiceCapableConnection service = (IServiceCapableConnection)
conn;
            // I want to send the new client name to clients
            service.invoke ("addUserToList",new Object[]{client.getAttribute
("name")});
        }
        return true;
    }

This is strange but Client1 connect: I see "App join by Client1" and de
"addUserToList" isn't called
I add Client2, I see "App joined by Client2", now Client1 receive "Client1"
in "addToUserList"
I add Client3, I see "App joined by Client3", now Client1 receive "Client1"
(again) in "addToUserList" and Client2 receive "Client2"...

I dont understand why, please help...


2008/2/19, Patrice FERLET <metal3d at gmail.com>:
>
> Really I've got problem to understand.
>
> This is my code (don't worry, I know I have develop 2 times the same code,
> but it was to understand):
> public boolean appConnect(IConnection conn, Object[] params) {
>         //record name
>         conn.getClient().setAttribute("name", params[0]);
>
>         //I try to send name to every clients...
>         IScope sc = conn.getScope();
>         Iterator<IConnection> connections = sc.getConnections();
>         while(connections.hasNext()){
>             System.out.println("into appconnect...");
>             IConnection conn1 = connections.next();
>             IServiceCapableConnection service =
> (IServiceCapableConnection) conn1;
>             service.invoke ("addUserToList",new Object[]{conn1.getClient
> ().getAttribute("name")});
>         }
>         return true;
>     }
>
>     public boolean appJoin(IClient client, IScope app){
>         System.out.println("App joined");
>         Iterator<IConnection> connections =  app.getConnections();
>         while(connections.hasNext()){
>             System.out.println("into appjoin...");
>             IConnection conn = connections.next();
>             IServiceCapableConnection service =
> (IServiceCapableConnection) conn;
>             service.invoke ("addUserToList",new Object[]{conn.getClient
> ().getAttribute("name")});
>         }
>         return true;
>     }
>
> Now, I run my first client with "username" set tu "u1". I see in console:
>  [java] u1
>  [java] App joined
> So it doesn't check the current connection...
>
> I add another client, name is set to u2:
> [java] u2
> [java] into appconnect...
> [java] App joined
> [java] into appjoin ...
>
> 2 connections are checked, but my first client insert 2 time my "u1" in
> list... client 2 don't have any name recieved...
>
> I add a third client name u3:
>  [java] u3
>  [java] fefef
>  [java] into appconnect...
>  [java] into appconnect...
>  [java] App joined
>  [java] into appjoin...
>  [java] into appjoin...
>
> Now, client 1 have 4 "u1" recieved... client 2 have 2 "u2" recieved and
> client 3 has no user recieved...
>
> It seems that iterator for IConnection conn = connections.next(); returns
> the same object each time for each client... It's really strange...
>
> What have i do wrong ?
>
> 2008/2/16, Andy <bowljoman at hotmail.com>:
> >
> >
> >       What I do in red5 app connect is something like...
> >
> >         conn.getClient().setAttribute("name", param[x]);
> >
> >         If you add a public method on your NetConnection.client....
> >
> >         Public function userPart(name:string):void
> >         {
> >
> >         }
> >
> >         you can do something like this in java...
> >
> >          @Override
> >         public void roomLeave(IClient client,IScope room)
> >         {
> >                 String name=(String)client.getAttribute("name");
> >                 client.setAttribute("room", "lobby");
> >                 Iterator<IConnection> conns3 =room.getConnections();
> >
> >                 while(conns3.hasNext())
> >                 {
> >                         try{ //to notify clients
> >                                 IConnection conn1=conns3.next();
> >
> >
> > ((IServiceCapableConnection)conn1).invoke("userPart",new
> > Object[]{name},this);
> >                         }catch(Exception e){}
> >                 }
> >            }
> >
> > Andy
> >
> >
> > -----Original Message-----
> > From: red5-bounces at osflash.org [mailto:red5-bounces at osflash.org] On
> > Behalf Of Patrice FERLET
> > Sent: Friday, February 15, 2008 4:31 PM
> > To: red5 at osflash.org
> > Subject: Re: [Red5] Creating chatromm. How to send to any clients ?
> >
> > I realize that you're right. Invoke method is the better way to do.
> > I will try to implement what you told me to code.
> >
> > Thanks
> > 2008/2/16, Patrice FERLET <metal3d at gmail.com>:
> > You seems telling about locals SharedObjects. Several examples on
> > internet explains that Shared Objects are used to create chatrooms. My
> > example only send a message, but i only think to use it to prevent
> > clients to check "sended messages"... in fact this is what i will do:
> >
> >     - Netconnection to my app
> >     - onSendMessage (send button clicked): call
> > myApp.sendMessage(username,message) -> stored on server
> >         -> then send "Message" on remoteSharedObject
> >     - onMessage (sharedobject handler) : call myApp.getMessage()
> >         -> then write on "chat interface"
> >
> > I only will send basics events message to client. Clients will call
> > Application method to get messages.
> >
> > The real benefits to use SharedObject here is to be easilly synchronized
> > with clients... Am i really wrong ?
> > 2008/2/15, Dominick Accattato <daccattato at gmail.com>:
> > Here's a simple thing to remember:
> >
> > Use SharedObjects for data synchronization and storage (example: setting
> > positional data on a 3d object and persist it for a later session)
> > Use invoke to perform a process on clients (example: telling a client
> > they have been banned from a chatroom)
> >
> > There's already enough documentation out there to explain why, but that
> > is how I generally write my applications and I've been building live
> > apps for quite some time.
> >
> > On Feb 15, 2008, at 3:27 PM, Patrice FERLET wrote:
> >
> > allright, this is how i did for my test. It's very simple, quickly coded
> > and it works. I did it on openLaszlo, but you can easilly convert it for
> > you Flash generators:
> >
> > <canvas debug="true">
> > <script>
> > //create my NetConntection
> > mync = new NetConnection();
> > mync.connect("rtmp://localhost/MyApp");
> >
> > mync.onStatus = function (state){
> >     if(state.code == "NetConnection.Connect.Success"){
> >         createSharedObject();
> >     }
> > }
> >
> >
> > function createSharedObject(){
> >
> >    so = SharedObject.getRemote("test", mync.uri, false); // fals = if
> > every clients are disconnected, the shared object is deleted on server
> >
> >    // I declare the "testMsg" handler
> >     so.testMsg = function (msg){
> >         Debug.write('Get Message');
> >         Debug.write(msg) // write "Hello" on my debug trace
> >     }
> >     so.connect(mync);
> >
> > }
> > </script>
> >
> > <button text="Test send Hello">
> >     <handler name="onclick">
> >         //I send "Hello" to testMsg handlers on every clients
> >         so.send("testMsg","Hello");
> >     </handler>
> > </button>
> > </canvas>
> >
> >
> > Open 2 players, and press the button... both clients get "Hello".
> > MyApp is an empty application for now. It's works !
> >
> > Very very nice ! I love !
> > 2008/2/15, Patrice FERLET <metal3d at gmail.com>:
> > I just looked how it works. Shared Objects are really nices.
> > In fact, there is 2 shared objects you can use:
> >   - local -> works like a cookie
> >   - remote -> works like a pipe
> >
> > If you get a SharedObject from Red5, you could get informations by
> > listening events:
> >   - onSync
> >   - onRelease
> >
> > I am working with it and i will purpose tutorials this week end. Not too
> > bad for a novice, isn't it ? :)
> >
> > PS: excuse my french english :)
> >
> > 2008/2/15, Ignacio Lopez <ignacio.lopez at gmail.com>:
> > I have implemented a very simple chat system with red5 and openlaszlo
> > using rtmp calls and server side state, and it's working fine so far.
> > However, i'am not so familiar with the sharedobject approach. What would
> > be the differences / benefits of using the shared object approach
> > instead of the traditional calls between clients and server?
> >
> > On Fri, Feb 15, 2008 at 7:52 AM, Joao Henrique Silva Santos
> > <joao.s.santos at gmail.com> wrote:
> > It is a shame to say it, but I still have not played with shared
> > objects and don't know the syntax, so I cannot help you. For the
> > moment I am using the "invoke" approach.
> > I would like to see other people responses, though.
> >
> > joao
> >
> > On 15/02/2008, Patrice FERLET <metal3d at gmail.com> wrote:
> > > In my last message, replace "oflaDemo" by "SOSample". I'm looking on
> > API
> > > documentation to find the way. I learn lot of good knowlegdes by
> > reading
> > > API.
> > >
> > > 2008/2/15, Patrice FERLET <metal3d at gmail.com>:
> > > > While you answered me, I was seeking again on red5 examples. I
> > founded the
> > > SimpleChat example working very well.
> > > > It seems to use oflaDemo application to connect and send messages...
> > but
> > > java sources are empties. I looked into directories and i found the
> > > simpleChat.fla sources...
> > > >
> > > > But on Linux, i can't decompile fla files to see how it works. I
> > didn't
> > > tried your code yet, but it seems that we can do it simply with
> > > SharedObject, right ?
> > > >
> > > > I'm not using flex but openlaszlo, working fine with red5.
> > > >
> > > > Thanks for your help.
> > > >
> > > >
> > > >
> > > > 2008/2/14, Joao Henrique Silva Santos <joao.s.santos at gmail.com>:
> > > >
> > > > > also, you may need to define a function on your client side:
> > > > >
> > > > > public function onBWDone()
> > > > >
> > > > > {
> > > > > }
> > > > >
> > > > > On 14/02/2008, Patrice FERLET <metal3d at gmail.com> wrote:
> > > > >
> > > > > > Hi,
> > > > > > Well, now I have created a first application wich can get
> > messages
> > > from my
> > > > > > client.
> > > > > > Remember that i begin on Red5 developpement :)
> > > > > >
> > > > > > What i did is a simple callable method: public String
> > > sendMessage(String
> > > > > > clientname, String msg)...
> > > > > >  My client send a message via NetConnection and i log my
> > message.
> > > Everything
> > > > > > is allright :) But how can I send this message on clients
> > connected to
> > > my
> > > > > > app ?
> > > > > >
> > > > > > Client have a "onResult" connection handler wich can get
> > returned
> > > values...
> > > > > > but only for my client calls...
> > > > > >
> > > > > > my Application run in Singleton. Have clients to "check"
> > messages
> > > every 500
> > > > > > ms? or is there another way to have my messages as stream ?
> > > > > >
> > > > > > I dont find any example on internet, if you can help me to find
> > my way
> > > :)
> > > > > >
> > > > > > PS: In fact, Red5 isn't complicated... I just miss some advanced
> > > tutorials.
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Blog: http://www.metal3d.org
> > > > > > Copix: http://www.copix.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
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > >
> > > > Blog: http://www.metal3d.org
> > > > Copix: http://www.copix.org
> > >
> > >
> > >
> > > --
> > > Blog: http://www.metal3d.org
> > > Copix: http://www.copix.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
> >
> >
> >
> > --
> > Blog: http://www.metal3d.org
> > Copix: http://www.copix.org
> >
> >
> >
> > --
> > Blog: http://www.metal3d.org
> > Copix: http://www.copix.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
> >
> >
> >
> > --
> > Blog: http://www.metal3d.org
> > Copix: http://www.copix.org
> >
> >
> >
> > --
> > Blog: http://www.metal3d.org
> > Copix: http://www.copix.org
> >
> >
> > _______________________________________________
> > Red5 mailing list
> > Red5 at osflash.org
> > http://osflash.org/mailman/listinfo/red5_osflash.org
> >
>
>
>
> --
> Blog: http://www.metal3d.org
> Copix: http://www.copix.org
>



-- 
Blog: http://www.metal3d.org
Copix: http://www.copix.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/red5_osflash.org/attachments/20080219/32893170/attachment-0001.html 


More information about the Red5 mailing list