8 Replies Latest reply on Jan 12, 2009 10:33 AM by Michael Thornburgh

    Simple Text Chat using Stratus

    Pablo Davi Level 1
      I was created two netStream one receiver and other sender like show in DevNet ( http://www.adobe.com/devnet/flashplayer/articles/rtmfp_stratus_app_03.html ) but how to send one string came from textfield via netStream ?

      Any idea? Thanks in advance ...
        • 1. Re: Simple Text Chat using Stratus
          Michael Thornburgh Adobe Employee
          Once you have a publisher and subscriber(s)'s NetStreams connected together, the publisher can do a netStream.send("onTextMessage", "someText") to send the message to the subscribers. The subscriber's netStream.client object would have an onTextMessage method that would be called with the text message as its parameter, which you could then display.

          HTH.

          -mike

          • 2. Re: Simple Text Chat using Stratus
            Pablo Davi Level 1
            Thanks Mike, some questions: when i send message using netStream.send("onTextMessage", "someText") all the netStream receivers will see this message writed in textfield right? I will use one only swf file and into it create two netStream, but reading the article about Stratus i saw that when receive message need the 256Bit ID of sender, how receive this message and to send the ID? Have one way list all logged IDs ? Attached my first try code. Thanks for all XD
            • 3. Re: Simple Text Chat using Stratus
              Michael Thornburgh Adobe Employee
              In your code included above, you're setting "myID" to the ID of the Stratus server, which isn't what you want. When using Stratus, you must provide your own mechanism (example: a web service) to communicate the peer IDs of the peers with which you want to communicate.

              In your case, the publisher would store its peer ID (netConnection.nearID) somewhere where subscribers would be able to find it (such as a web service). Subscribers would fetch that peer ID and use it in the receiveMess() function to create the new NetStream. Also, to receive a NetStream.send(), you must create an object with the desired method name(s) and assign it to the subscriber NetStream's (your recvStream) client property.

              -mike
              • 4. Re: Simple Text Chat using Stratus
                Pablo Davi Level 1
                I tryed use .send method to transfer arguments to receiveMess function like code bellow but appear not run the function. Thanks again
                • 5. Re: Simple Text Chat using Stratus
                  Michael Thornburgh Adobe Employee
                  in the code you've attached, the "receiveMess" function can't be called because there's no NetStream already subscribed to "media" on which the "receiveMess" send would be received. in the code you attached, you are trying to create the channel on which to receive messages from the message handler. since no channel exists yet, the message can't be received, so the channel won't be created.

                  on the subscribing end, you must create the receive NetStream with the publisher's peerID, set up a client object to receive the .send()s, and do recvStream.play("media") before any .send()s will be received on that client object.

                  -mike

                  • 6. Re: Simple Text Chat using Stratus
                    Pablo Davi Level 1
                    Well, but how to create one channel to send and receive messages from it ?
                    • 7. Re: Simple Text Chat using Stratus
                      Michael Thornburgh Adobe Employee
                      NetStreams are one-directional. Only the publisher can use .send() (after doing .publish()), and only the subscribers will see the sent messages appear at their client objects (after doing a .play()). In order to do bidirectional communication, each end must publish a stream for the other end to play, and play the other end's published stream.

                      -mike

                      • 8. Re: Simple Text Chat using Stratus
                        Michael Thornburgh Adobe Employee
                        Note that the Stratus sample application

                        http://labs.adobe.com/technologies/stratus/samples/

                        includes a text-chat area in the middle of the window. You can look at how that works to see a fully working example using NetStream.send().

                        -mike

                        1 person found this helpful