3 Replies Latest reply on Jun 3, 2010 6:22 AM by k1ntar0

    NetGroup - cannot post message twice

    k1ntar0

      Lately, I've been trying to develop a simple flash game that uses the Adobe Stratus technology.

      I am using the NetGroup class to transfer messages among the players. In my game this only means transfering the controls.

      So it basically looks like this:

      private function keyPressed(evt:KeyboardEvent):void
      {
           if (evt.keyCode == cLeft) {
                p2pConnection.sendMessage("control", "left down");
           }
           if (evt.keyCode == cRight) {
                p2pConnection.sendMessage("control", "right down");
           }
      }
                
      private function keyReleased(evt:KeyboardEvent):void
      {
           if (evt.keyCode == cLeft) {
                p2pConnection.sendMessage("control", "left up");
           }
           if (evt.keyCode == cRight) {
                p2pConnection.sendMessage("control", "right up");
           }
      }
      

       

      And here is the sendMessage function:

      public function sendMessage(cmd:String, val:String):void
      {
           var query:Object = new Object();
           query.sender = nc.nearID;
           query.cmd = cmd;
           query.val = val;
           netGroup.post(query);
      }
      

       

      The weird thing now is that I can only post the same message once which means if I for instance press the left key twice, everybody only receives the "left down" message once. It's the same with all the other messages as well.

      The messages are handled via "NetGroup.Posting.Notify" which calls receiveMessage(event.info.message);

       

      Does anyone know how to solve this problem?

        • 1. Re: NetGroup - cannot post message twice
          Michael Thornburgh Adobe Employee

          this is from the ActionScript documentation for NetGroup.post():

           

            All messages must be unique. A message that is identical to one posted earlier might not be propagated. Use a sequence number to make messages unique.

          • 2. Re: NetGroup - cannot post message twice
            Michael Thornburgh Adobe Employee

            the *reason* why messages must be unique is: peers gossip with each other about the postings each has.  each posting is identified by its messageID, which is the SHA256 of the AMF serialization of the posting.  peers attempt to retrieve new postings they don't have already from peers that announce them.  a second posting of a message will have the same messageID, so peers will believe they already have the message and not retrieve/propagate it again.

             

            note that the documentation says duplicates *might* not be propagated -- messages eventually time out, but the timeout is not specified and may change in the future.

             

            well-behaved senders SHOULD assume that duplicates will not be propagated and ensure all messages are unique.  well-behaved receivers SHOULD assume that duplicates may be received (eventually) and, if that's a problem, take extra precautions to filter duplicates.

            • 3. Re: NetGroup - cannot post message twice
              k1ntar0 Level 1

              Ok thank you very much. This should solve my problem