This commit is contained in:
2014-06-23 07:46:03 +04:00
parent 1bf3e4cc80
commit 44c82ec71c
2 changed files with 59 additions and 27 deletions

View File

@@ -1,5 +1,7 @@
package ru.m.armageddon.client;
import haxe.io.BytesInput;
import flash.events.ProgressEvent;
import haxe.io.Bytes;
import flash.events.Event;
import flash.events.SecurityErrorEvent;
@@ -9,7 +11,6 @@ import haxework.log.TraceLogger;
import flash.net.Socket;
class Client {
private static inline var TAG = "Armageddon";
@@ -36,7 +37,9 @@ class Client {
socket.addEventListener(Event.CONNECT, onConnect);
//socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
//socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
//socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
//socket.endian = flash.utils.Endian.LITTLE_ENDIAN;
socket.connect("localhost", 5000);
}
@@ -50,4 +53,16 @@ class Client {
socket.writeShort(bytes.length);
socket.writeBytes(cast bytes.getData());
}
private function onSocketData(_) {
L.d(TAG, "onSocketData");
var b = new flash.utils.ByteArray();
L.d(TAG, "socket.bytesAvailable: " + socket.bytesAvailable);
socket.readBytes(b);
var bs = Bytes.ofData(cast b);
L.d(TAG, "bs.length: " + bs.length);
var response = new LoginResponse();
response.mergeFrom(bs);
L.d(TAG, response.user.login);
}
}