Jelajahi Sumber

detect close

Nicolas Cannasse 10 tahun lalu
induk
melakukan
620c1145b8
1 mengubah file dengan 7 tambahan dan 2 penghapusan
  1. 7 2
      hxd/net/Socket.hx

+ 7 - 2
hxd/net/Socket.hx

@@ -88,9 +88,13 @@ class Socket {
 			onConnect();
 			onConnect();
 		});
 		});
 		s.addEventListener(flash.events.IOErrorEvent.IO_ERROR, function(e:flash.events.IOErrorEvent) {
 		s.addEventListener(flash.events.IOErrorEvent.IO_ERROR, function(e:flash.events.IOErrorEvent) {
-			out = new SocketOutput();
+			close();
 			onError(e.text);
 			onError(e.text);
 		});
 		});
+		s.addEventListener(flash.events.Event.CLOSE, function(_) {
+			close();
+			onError("Closed");
+		});
 		s.connect(host, port);
 		s.connect(host, port);
 		#else
 		#else
 		throw "Not implemented";
 		throw "Not implemented";
@@ -100,7 +104,8 @@ class Socket {
 	public function close() {
 	public function close() {
 		#if flash
 		#if flash
 		if( s != null ) {
 		if( s != null ) {
-			try s.close() catch( e : Dynamic ) {};
+			try s.close() catch( e : Dynamic ) { };
+			out = new SocketOutput();
 			s = null;
 			s = null;
 		}
 		}
 		#else
 		#else