コード例 #1
0
 public async Task Start()
 {
     _listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 10010);
     _listener.ExclusiveAddressUse = false;
     _listener.Start();
     while (!_shutdown)
     {
         TcpClient client = null;
         try {
             client = await _listener.AcceptTcpClientAsync();
         }
         catch (ObjectDisposedException) {
             // will be thrown when you stop listener
         }
         if (client != null)
         {
             var tcpConnectedLogic = new TcpConnectionLogic(client);
             // start processing on thread pool thread if necessary
             // don't wait for it to finish - you need to accept more connections
             tcpConnectedLogic.StartAsync();
         }
     }
 }
コード例 #2
0
 public void OnConnectionClose(TcpConnectionLogic connection)
 {
     m_TcpConnections.Remove(connection);
     GameObject.Destroy(connection.gameObject);
 }