Strange Flash AS3 xml Socket Behavior

I have a problem that I cannot understand.

To understand this, I wrote a socket client on AS3 and a server on python / twisted, you can see the code of both applications below.

Allow two clients to start at the same time, arrange them so that you can see both windows and click the connect button in both windows. Then press and hold any button.

What I expect:

A client with a pressed button sends a β€œsome data” message to the server, then the server sends this message to all clients (including the original sender).

Then each client moves on the right button "connectButton" and prints a message to the log with time in the following format: "min: secs: milliseconds".

What's wrong:

The movement is smooth in the client that sends the message, but in all other clients the movement is jerky.

This is because messages for these clients arrive later than the original sending client. And if we have three clients (let's call them A, B, C) and we will send a message from A, the time log of sending B and C will be the same.

Why do other clients receive these messages later than the original sender?

By the way, on ubuntu 10.04 / chrome the whole movement is smooth. Two clients run in separate chromes.

window screenshot

linux screen shot

List of magazines, four clients at a time:

[16:29:33.280858] 62.140.224.1 >> some data [16:29:33.280912] 87.249.9.98 << some data [16:29:33.280970] 87.249.9.98 << some data [16:29:33.281025] 87.249.9.98 << some data [16:29:33.281079] 62.140.224.1 << some data [16:29:33.323267] 62.140.224.1 >> some data [16:29:33.323326] 87.249.9.98 << some data [16:29:33.323386] 87.249.9.98 << some data [16:29:33.323440] 87.249.9.98 << some data [16:29:33.323493] 62.140.224.1 << some data [16:29:34.123435] 62.140.224.1 >> some data [16:29:34.123525] 87.249.9.98 << some data [16:29:34.123593] 87.249.9.98 << some data [16:29:34.123648] 87.249.9.98 << some data [16:29:34.123702] 62.140.224.1 << some data 

AS3 client code , I left only the corresponding part, the full code is here .

  private var socket :XMLSocket; socket = new XMLSocket(); socket.addEventListener(DataEvent.DATA, dataHandler); private function dataHandler(event:DataEvent):void { var now:Date = new Date(); textField.appendText(event.data + " time = " + now.getMinutes() + ":" + now.getSeconds() + ":" + now.getMilliseconds() + "\n"); connectButton.x += 2; } private function keyDownHandler(event:KeyboardEvent):void { socket.send("some data"); } private function connectMouseDownHandler(event:MouseEvent):void { var connectAddress:String = "ep1c.org"; var connectPort:Number = 13250; Security.loadPolicyFile("xmlsocket://" + connectAddress + ":" + String(connectPort)); socket.connect(connectAddress, connectPort); } 

Python server code .

+6
source share
2 answers

You may encounter some combination of ACK delay and / or Nagle algorithm . Both of them can selectively delay data movement in a TCP session, and their implementations vary widely on the platform.

Try using setsockopt() with TCP_NODELAY on the socket to disable Nagle.

AFIK, Windows does not allow you to disable ACK delay for each socket: you must edit the registry and disable it for all TCP. So try TCP_NODELAY first. If this does not work, experiment with disabling the ACK delay. Even if editing the registry is impractical for your application, just knowing whether ACK latency is a problem, you can point in the right direction for other workarounds.

+4
source

I know this is a bit late, but most likely this is due to the time required to configure the TCP connection between the server and the non-initializing client.

The idea is that there is already a TCP connection established between the initiating client and the server (setting it up to the first client message), so in this case the time required for a three-way handshake is eliminated.

You can test this in several ways, the easiest of which is to establish a connection before your actual processing of messages (for example, by sending a dummy message to each of them).

You can also switch to UDP if you do not want to establish a connection with each client, but then you lose the reliability of TCP.

I'm not sure I understood your Linux post. Are you saying this works on Linux, but not on Windows? If so, do we need to know more about your setup, for example, all clients running on the same host? In the same browser instance?

+1
source

Source: https://habr.com/ru/post/906469/


All Articles