示例#1
0
        /// <summary>
        /// Thread which listens for remotely connected clients.
        /// </summary>
        private void ListenForClients()
        {
            started = true;
            TcpListener tcpListener = new TcpListener(IPAddress.Any, _port);            //TODO: Add support for specified IP addresses.

            tcpListener.Start();
            while (true)
            {
                //Blocks the thread until a client had connected.
                TcpClient RemoteTcpClient = tcpListener.AcceptTcpClient();
                //new TcpClient() { Client = tcpListener.Server.Accept(); };
                SessionStartedEventArgs e = new SessionStartedEventArgs((IPEndPoint)RemoteTcpClient.Client.RemoteEndPoint, RemoteTcpClient);
                MinecraftBot.Events.RaiseSessionStarted(e);
                //Create a thread to handle communication with the connected remote client.
                RemoteClient client       = new RemoteClient();
                Thread       clientThread = new Thread(delegate() { client.Start(RemoteTcpClient, this); });
                clientThread.Start();
                Clients.Add(client);
            }
        }
示例#2
0
 /// <summary>
 /// Thread which listens for remotely connected clients.
 /// </summary>
 private void ListenForClients()
 {
     started = true;
     TcpListener tcpListener = new TcpListener(IPAddress.Any,_port); //TODO: Add support for specified IP addresses.
     tcpListener.Start();
     while (true)
     {
         //Blocks the thread until a client had connected.
         TcpClient RemoteTcpClient = tcpListener.AcceptTcpClient();
         //new TcpClient() { Client = tcpListener.Server.Accept(); };
         SessionStartedEventArgs e = new SessionStartedEventArgs((IPEndPoint)RemoteTcpClient.Client.RemoteEndPoint,RemoteTcpClient);
         MinecraftBot.Events.RaiseSessionStarted(e);
         //Create a thread to handle communication with the connected remote client.
         RemoteClient client = new RemoteClient();
         Thread clientThread = new Thread(delegate() { client.Start(RemoteTcpClient,this); } );
         clientThread.Start();
         Clients.Add(client);
     }
 }