Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Client Getting Different Messages Than Other Client in TCP Sockets?

Explorer ,
Apr 25, 2015 Apr 25, 2015

socket server, and though it does work alright, occasionally one of the clients will get a message that the other one won't. It SHOULDN'T be packet loss, but I really don't understand how one of them isn't getting a message the other one is... how did I code it? Here's how. This is part of the server:

function socketDataHandler(event:ProgressEvent):void

{

    var socket:Socket = event.target as Socket;

    var message:String = socket.readUTFBytes(socket.bytesAvailable);

    for each (var socket:Socket in clientSockets)

    {

            if (message.indexOf("p1") >= 0)

            {

                msg1 = message;

                socket.writeUTFBytes(msg1+msg2);

                socket.flush();

                continue;

            }

            if (message.indexOf("p2") >= 0)

            {

                msg2 = message;

                socket.writeUTFBytes(msg1+msg2);

                socket.flush();

                continue;

            }

The clients (p1 and p2) send messages whenever specific keys are pressed, moving their characters around. I have sort of a unique system as I couldn't really find a way to send multiple individual signals after looking and asking around Google for WEEKS, but instead each player sends one single string of what keys are pressed. Those strings are determined by what combination of keys are being pressed and not pressed at a time. For example, if the down key and the left key are both being pressed, the string would be something like "p1_down0_down p1_left0_down p1_up0_up p1_right0_up p1_attack0_up". That is the one message that sends from p1. For p2, it's the same thing, only with p2 in place of p1. lol.

Here's a part of the client's programming:

if (msg.indexOf("p2_right0_down") >= 0)

    {

                p2_right = "down";

        }

    if (msg.indexOf("p2_down0_down") >= 0)

    {

                p2_down = "down";

    }

  if (msg.indexOf("p1_right0_down") >= 0)

    {

                p1_right = "down";

    }

Simple, huh? It uses indexOf to find parts of the string, and if said parts are found, it takes effect to the character's keys being pressed, thus setting off the scripts in the game to move them around, attack, etc.

And get this... the characters' movements do NOT take place UNTIL the signal has reached the client... that's right, even the one pressing the keys in the first place. It will not move the character around until the messages have been sent to the server and then sent back to both the sender and the other client. And though this does work absolutely perfectly most of the time, occasionally if I try and press the keys fast in some certain combination, OCCASIONALLY the player will go off-course in one of the clients. How is this happening? Your guess is as good as mine because as far as my knowledge goes this shouldn't be happening whatsoever... BOTH of the clients are getting the same messages... so if anyone were to go off-course, it would be with BOTH of the clients and then in the end the course would be the same thing... HOW ON EARTH is ONE of the clients not responding correctly?? This simply does not make any sense to me...

TOPICS
ActionScript
242
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 26, 2015 Apr 26, 2015
LATEST

I would suggest adding some logging to both your server and clients so you can see exactly what is being sent and received.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines