本文整理汇总了C#中Fleck.WebSocketServer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocketServer.Dispose方法的具体用法?C# WebSocketServer.Dispose怎么用?C# WebSocketServer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fleck.WebSocketServer
的用法示例。
在下文中一共展示了WebSocketServer.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WebsocketProcessor
public WebsocketProcessor(string uri)
{
//Websocket clients container
_clients = new List<IWebSocketConnection>();
//Websocket server start
_ws = new WebSocketServer(uri);
_ws.Start(socket =>
{
socket.OnOpen = () => OnOpen(socket);
socket.OnClose = () => OnClose(socket);
socket.OnMessage = OnWsMessage;
});
//Event from ep source
OnSourceEvent = (@event, point) =>
{
// if (@event.Type != Channel && !string.IsNullOrEmpty(@event.Type)) return;
var json = JsonConvert.SerializeObject(@event, Formatting.Indented);
foreach (var client in _clients)
{
client.Send(json);
}
};
//Error from ep source
OnSourceError = (exception, sender) =>
{
//Close websocket clients
foreach (var client in _clients)
client.Close();
Log.Debug("error sent to websocket clients");
};
//Close connection with ep source
OnSourceClose = (sender) =>
{
//Close websocket clients
foreach (var client in _clients)
client.Close();
_ws.Dispose();
Log.Debug("Websocket closed on source close");
};
}
示例2: Main
//.........这里部分代码省略.........
);
};
socket.OnClose = () =>
{
if (!Clients.Contains(socket)) //ne obdelaj nic, ta socket je ocitno bil zavrzen ker je server pun.
return;
Clients.Remove(socket);
restart = true;
Console.WriteLine("Client disconnected!");
};
socket.OnMessage = message =>
{
if (Clients.Count == 0)
return;
else if( !Clients.Contains(socket))
{
Console.WriteLine("Closed anonymous socket!");
socket.Close();
}
dynamic Respond = Json.Decode(message);
// Console.WriteLine(Respond.H);
if (Clients.First() == socket)
{
if (Respond.H == 2) //Podatki o igri!
{
StartGameJson = message;
return;
}
if (Respond.H == 1111) //Game koncan!
{
Console.WriteLine("Game over!");
BroadCast(jsonRequest(4, -1, true, 0, 0, 30)); //Ultra reset!
return;
}
if (Respond.H == 1000) //Game se tece!
{
Console.WriteLine("Game running!");
firstRun = false;
return;
}
if (Respond.H == 1001)
{
Console.WriteLine("Game is in waiting.");
if (firstRun)
return;
StartGameJson = "";
SentGameRequest = false;
GameRunning = false;
return;
}
}
if (StartGameJson != "" && GameRunning && Respond.H == 3)
{
BroadCast(message);
}
};
});
System.Timers.Timer ServerChecker = new System.Timers.Timer(3000);
ServerChecker.Elapsed += (obj, e) =>
{
if (Clients.Count != 0)
{
//TO je blo prvotno misleno za enega samo... Clients.first.send...
BroadCast(jsonRequest(4, 0, true, Clients.Count, NUMBER_OF_PLAYERS, 20)); //Zahtevaj stanje na serveru :) POSLJI INFORMACIJO KOLKO CLIENTOV OD KOLKIH JE GOR!
}
};
ServerChecker.Enabled = true;
while (!restart)
{
if (Clients.Count == NUMBER_OF_PLAYERS && !GameRunning)
{
if (SentGameRequest && StartGameJson != "")
{
BroadCast(StartGameJson); //H = 2
GameRunning = true;
}
else if (!SentGameRequest)
{
SentGameRequest = true;
Clients.First().Send(
jsonRequest(0, -1, true, 0, 0, 0) //REQUESTAJ MAPO IN SETAJ ID //H=0
);
}
}
Console.WriteLine("Clients #:" + Clients.Count.ToString());
Thread.Sleep(1000);
}
for (int i = 0; i < Clients.Count; i++)
{
Clients[i].Close();
}
server.Dispose();
server = null;
Console.WriteLine("RESTARTING SERVER");
}
}