39 lines
979 B
C#
39 lines
979 B
C#
using Fleck;
|
|
using System;
|
|
|
|
|
|
namespace BattleServer
|
|
{
|
|
|
|
/// <summary>
|
|
/// 服务端
|
|
/// </summary>
|
|
class Service
|
|
{
|
|
public static Service Instance;
|
|
private WebSocketServer server;
|
|
private List<Client> clients;
|
|
|
|
///addr("ws://127.0.0.1:9897")
|
|
public Service(string addr)
|
|
{
|
|
var server = new WebSocketServer(addr); //创建webscoket服务端实例
|
|
server.Start(onAccept);
|
|
clients = new List<Client>();
|
|
Instance = this;
|
|
}
|
|
|
|
private void onAccept(IWebSocketConnection webSocket)
|
|
{
|
|
Client client = new Client(webSocket);
|
|
Console.WriteLine("新的连接对象进入{0}", client.ToString());
|
|
clients.Add(client);
|
|
}
|
|
|
|
public void Shutdown(Client client)
|
|
{
|
|
Console.WriteLine("连接对象断开{0}", client.ToString());
|
|
this.clients.Remove(client);
|
|
}
|
|
}
|
|
} |