diff --git a/Client.cs b/Client.cs
index 55e6df9..f377022 100644
--- a/Client.cs
+++ b/Client.cs
@@ -13,6 +13,11 @@ namespace BattleServer
{
socket = _socket;
socket.OnBinary = doBinary;
+ socket.OnClose = close;
+ }
+
+ private void close (){
+ Service.Instance.Shutdown(this);
}
///
diff --git a/Service.cs b/Service.cs
index 733e7d9..be12cf1 100644
--- a/Service.cs
+++ b/Service.cs
@@ -10,6 +10,7 @@ namespace BattleServer
///
class Service
{
+ public static Service Instance;
private WebSocketServer server;
private List clients;
@@ -18,6 +19,7 @@ namespace BattleServer
var server = new WebSocketServer("ws://127.0.0.1:9897"); //创建webscoket服务端实例
server.Start(onAccept);
clients = new List();
+ Instance = this;
}
private void onAccept(IWebSocketConnection webSocket)
@@ -26,5 +28,10 @@ namespace BattleServer
Console.WriteLine("新的连接对象进入{0}", client.ToString());
clients.Add(client);
}
+
+ public void Shutdown(Client client){
+ Console.WriteLine("连接对象断开{0}", client.ToString());
+ this.clients.Remove(client);
+ }
}
}
\ No newline at end of file