# Send Multiple writeUTF Messages Across Socket in AS3?

**URL:** <https://forum.kirupa.com/t/send-multiple-writeutf-messages-across-socket-in-as3/623978>\
**Category:** flash\
**Created:** [April 20, 2015, 6:31pm UTC](https://forum.kirupa.com/t/send-multiple-writeutf-messages-across-socket-in-as3/623978 "2015-04-20T18:31:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Twisted4000](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Twisted4000](https://forum.kirupa.com/u/Twisted4000)\
**Post date:** [April 20, 2015, 6:31pm UTC](https://forum.kirupa.com/t/send-multiple-writeutf-messages-across-socket-in-as3/623978/1 "2015-04-20T18:31:44Z")

</div>

So with TCP in AS3, I’m trying to write strings over to the server  
and then to the clients, but it appears to only be able to read one at a  
time. This is not good because I’m sending messages based on keys being  
pressed, and the client has an action that needs to be taken place  
based on what key is pressed. Since multiple keys can be pressed at a  
time, obviously it does not work correctly.

Client example:

```
if (keys[p1_jump_key])
        {
            p1_up = "down";
            sock.writeUTF("p1_up_down");
            sock.flush();
        }
        else
        {
            p1_up = "up";
            sock.writeUTF("p1_up_up");
            sock.flush();
        }
        if (keys[p1_crouch_key])
        {
            p1_down = "down";
            sock.writeUTF("p1_down_down");
            sock.flush();
        }
        else
        {
            p1_down = "up";
            sock.writeUTF("p1_down_up");
            sock.flush();
        }

```

And then here is the server:

```
function socketDataHandler(event:ProgressEvent):void{
var socket:Socket = event.target as Socket;
var message:String = socket.readUTF();
for each (var socket:Socket in clientSockets)
{
        socket.writeUTF(message);
        socket.flush();
}
}

```

And finally, here is the receiving client (I have a method that allows the server to differentiate between the two):

```
if(msg=="p1_down_down"){
        p1_down="down";
    }
    if(msg=="p1_down_up"){
        p1_down="up";
    }
    if(msg=="p1_up_down"){
        p1_down="down";
    }
    if(msg=="p1_up_up"){
        p1_down="up";
    }

```

Now many of you may already see the issue, as when the down key is up, it  
sends the message “p1\_down\_up”. When the up key is up, it sends the  
message “p1\_up\_up”. Both messages are sending at once when neither of  
them are being pressed. The receiving client is, I suppose, just getting  
one of the signals, or perhaps neither of them. How do I make MULTIPLE  
signals get wrote and read over the server? I tried using an array but  
you can’t write those apparently. Thank you.
