3 Replies Latest reply on Feb 9, 2011 5:34 PM by Michael Thornburgh

    How to send object by NetStream?

    swoorn

      Hi, I have question about using Cirrus in real time game developed. I want to create a game in which each player will be able to move a character using the arrow keys. And here comes my question.How do I continuously transfer an object or variable via NetStream. Should I use the send() method (when a player is in motion), or maybe it's possible to send and receive an object using publish() and play().

       

      I spent a lot of time looking for solutions on the internet, but with no succes. Everything that I've found was about transmission of audio and video (attachAudio() and attachVideo()), I need a method such as attachObject(), which could continuously send for example player's position.

       

      I found P2PGameLibrary on Tom Krcha's site (www.flashrealtime.com). Unfortunately, it is in the  .swc file and when I use FlashDevelop to open it, it shows only the model of classes and methods. If I could see the entire code, I could study it and maybe it would solve my problem.

       

      If someone could give an example of how to send objects/variables by NetStream, I would be grateful.

       

      swO_orn

        • 1. Re: How to send object by NetStream?
          PresentOnline

          Swoorn

          Check out the netstream doco on adobe site.

          you got 2 options to send data by p2p

          1) netstream send (for a relatively small % of memebers of the group

          sending info out). does not sound like your route as I imagine you want

          all the players to broadcast their info

          2) netgroup.post()  (for many to many messaging of "small" objects) ,

          this seems more appropriate for your use case.

           

          A good starting point would be a sample p2p chat project that works, and

          add the login to post when the character moves.

           

          Cheers.

          • 2. Re: How to send object by NetStream?
            swoorn Level 1

            Thanks for fast answer.

            Yes I have build a simple chat p2p using only NetGroup, and sending messages by method post(). The one "bad thing" I nothiced is delay. I got about 500ms. That's too much for real time games.

            I have watch some tutorials on Tom Krcha's blog and they said I should build full mesh of direct connections of all users to make P2P game.

            Let's say I want to have 6 players sending and receiving info in game. What's the best way to transfer data between them? NetGroup.post() or NetStream.send() or maybe another?

             

            PS: Please give me an example how to receive data in NetStream if data was transfered by send() method.

            Doc says :

            send(handlerName:String, ... arguments):void

            How do I start handler on receiver app?
            • 3. Re: How to send object by NetStream?
              Michael Thornburgh Adobe Employee

              NetGroup.post() is not appropriate for a real-time game, as you've discovered.  there could be a large delay, and messages could arrive out-of-order.  NetStream.send() on 1:1 P2P NetStreams is the most appropriate for your use case.  you can use a timer to send updates at intervals.