-
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
package ru.m.armageddon.client;
|
||||
|
||||
import haxe.io.BytesInput;
|
||||
import flash.events.ProgressEvent;
|
||||
import haxe.io.Bytes;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.events.Event;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.events.IOErrorEvent;
|
||||
import haxe.io.BytesOutput;
|
||||
import ru.m.armageddon.core.connect.FlashConnection;
|
||||
import ru.m.armageddon.core.connect.IConnection;
|
||||
import haxework.log.TraceLogger;
|
||||
import flash.net.Socket;
|
||||
|
||||
|
||||
class Client {
|
||||
|
||||
@@ -22,47 +17,20 @@ class Client {
|
||||
}
|
||||
|
||||
|
||||
private var socket:Socket;
|
||||
private var connection:IConnection;
|
||||
|
||||
public function new() {
|
||||
connection = new FlashConnection("localhost", 5000, onConnect);
|
||||
|
||||
socket = new Socket();
|
||||
socket.addEventListener(IOErrorEvent.IO_ERROR, function(error):Void {
|
||||
L.e("SocketLogger", "", error);
|
||||
flash.Lib.current.addEventListener(MouseEvent.CLICK, function(_) {
|
||||
onConnect(_);
|
||||
});
|
||||
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(error):Void {
|
||||
L.e("SocketLogger", "", error);
|
||||
});
|
||||
//socket.addEventListener(Event.CLOSE, closeHandler);
|
||||
socket.addEventListener(Event.CONNECT, onConnect);
|
||||
//socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
|
||||
//socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
|
||||
socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
|
||||
//socket.endian = flash.utils.Endian.LITTLE_ENDIAN;
|
||||
|
||||
socket.connect("localhost", 5000);
|
||||
}
|
||||
|
||||
private function onConnect(_) {
|
||||
public function onConnect(event:Event):Void {
|
||||
var request = new LoginRequest();
|
||||
request.login = "shmyga";
|
||||
request.password = "xkbp8jh9z2";
|
||||
var out = new BytesOutput();
|
||||
request.writeTo(out);
|
||||
var bytes = out.getBytes();
|
||||
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);
|
||||
connection.send(request);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user