-
This commit is contained in:
@@ -5,6 +5,7 @@ import protohx.Message;
|
||||
import ru.m.armageddon.core.connect.IConnection;
|
||||
|
||||
class BaseConnection implements IConnection {
|
||||
public var connected(default, null):Bool;
|
||||
|
||||
private var builder:IPacketBuilder;
|
||||
private var handler:IConnectionHandler;
|
||||
@@ -14,6 +15,8 @@ class BaseConnection implements IConnection {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public function connect():Void {}
|
||||
|
||||
public function pushData(bytes:Bytes):Void {}
|
||||
|
||||
public function send(packet:Message):Void {}
|
||||
|
||||
@@ -4,8 +4,12 @@ import haxe.io.Bytes;
|
||||
import protohx.Message;
|
||||
|
||||
interface IConnection {
|
||||
public var connected(default, null):Bool;
|
||||
|
||||
private var builder:IPacketBuilder;
|
||||
private var handler:IConnectionHandler;
|
||||
|
||||
public function connect():Void;
|
||||
public function send(packet:Message):Void;
|
||||
public function pushData(bytes:Bytes):Void;
|
||||
private function receive(packet:Message):Void;
|
||||
|
||||
@@ -14,10 +14,15 @@ import flash.net.Socket;
|
||||
|
||||
class FlashConnection extends BaseConnection {
|
||||
|
||||
private var host:String;
|
||||
private var port:Int;
|
||||
private var socket:Socket;
|
||||
|
||||
public function new(host:String, port:Int, handler:IConnectionHandler) {
|
||||
super(handler);
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
connected = false;
|
||||
socket = new Socket();
|
||||
socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
|
||||
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
|
||||
@@ -25,18 +30,27 @@ class FlashConnection extends BaseConnection {
|
||||
socket.addEventListener(Event.CONNECT, onConnect);
|
||||
socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
|
||||
socket.endian = Endian.LITTLE_ENDIAN;
|
||||
//socket.connect(host, port);
|
||||
}
|
||||
|
||||
override public function connect():Void {
|
||||
socket.connect(host, port);
|
||||
}
|
||||
|
||||
private function onError(event:ErrorEvent):Void {
|
||||
socket.close();
|
||||
connected = false;
|
||||
handler.onError(event);
|
||||
}
|
||||
|
||||
private function onConnect(_):Void {
|
||||
connected = true;
|
||||
handler.onConnected();
|
||||
}
|
||||
|
||||
private function onClose(_):Void {
|
||||
socket.close();
|
||||
connected = false;
|
||||
handler.onDisconnected();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user