Actually, I need low latency communication with high performance server side, but it looks like I can't control the latency and lua is look too slow for my task. About latency: I send the data every 100 msec from the client using stream:
_sendStream = new NetStream(_connection.connection);
_sendStream.addEventListener( NetStatusEvent.NET_STATUS, OnSendBufferEvent );
_sendStream.dataReliable = false;
_sendStream.publish(_connection.userName,"live");
[...]
private function onTimer(e:TimerEvent):void {
if (_sendStream != null) {
_sendStream.send("OnData", String(_curFrame));
_curFrame = _curFrame + 1;
}
}
On server side I receive the data and send it back to the user using RPC:
function onDataPacket(client,publication,name,packet)
[...]
client.writer:writeAMFMessage("onPlayerPacket", client.userName, packet);
[...]
end
and client side call back function just prints interval between two calls:
var _timerVal:int = 0;
private function onPlayerPacket(playerName:String, packet:String) : void
{
var nval:int = getTimer();
trace(playerName + " : " + packet + " in (msec) " + (nval- _timerVal));
_timerVal = nval;
}
And here is what we get:
aaaaa : 0 in (msec) 4611
aaaaa : 1 in (msec) 0
aaaaa : 2 in (msec) 0
aaaaa : 3 in (msec) 0
aaaaa : 4 in (msec) 0
aaaaa : 5 in (msec) 0
aaaaa : 6 in (msec) 0
aaaaa : 7 in (msec) 0
aaaaa : 8 in (msec) 0
aaaaa : 9 in (msec) 2017
aaaaa : 10 in (msec) 0
aaaaa : 11 in (msec) 0
aaaaa : 12 in (msec) 0
aaaaa : 13 in (msec) 0
aaaaa : 14 in (msec) 0
aaaaa : 15 in (msec) 0
aaaaa : 16 in (msec) 0
aaaaa : 17 in (msec) 0
aaaaa : 18 in (msec) 0
aaaaa : 19 in (msec) 0
aaaaa : 20 in (msec) 0
aaaaa : 21 in (msec) 0
aaaaa : 22 in (msec) 0
aaaaa : 23 in (msec) 0
aaaaa : 24 in (msec) 0
aaaaa : 25 in (msec) 17
aaaaa : 26 in (msec) 0
aaaaa : 27 in (msec) 0
aaaaa : 28 in (msec) 0
aaaaa : 29 in (msec) 1983
So, it looks like RPC latency is about 2 seconds.