本文整理汇总了C#中MessageHandler.AddClient方法的典型用法代码示例。如果您正苦于以下问题:C# MessageHandler.AddClient方法的具体用法?C# MessageHandler.AddClient怎么用?C# MessageHandler.AddClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageHandler
的用法示例。
在下文中一共展示了MessageHandler.AddClient方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Console.WriteLine("Server Started...");
MessageHandler msgHandler = new MessageHandler();
var port = Shared.port;
// Create single TcpListener
var listener = new TcpListener (IPAddress.Any, port);
listener.Start();
new Thread(PingClients).Start(msgHandler);
while (true)
{
// Wait for client connection (accept socket)
var socket = listener.AcceptSocket();
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, SOCKET_TIMEOUT);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, SOCKET_TIMEOUT);
// Create stream
var stream = new NetworkStream(socket);
// Create reader
var streamr = new StreamReader(stream);
// Create writer
var streamw = new StreamWriter(stream);
streamw.AutoFlush = true;
// Add new client to MessageHandler
msgHandler.AddClient(streamw, socket);
// Create a thread that handles reading from the client (pass the reader)
var thread = new Thread (HandleClient);
thread.Start(Tuple.Create<StreamReader, MessageHandler, Socket>(streamr, msgHandler, socket));
}
}