Exemplo n.º 1
0
        /// <summary>
		/// Main accept thread proc
		/// </summary>
		private void AcceptThread()
		{
            Socket client = null;
            try
			{
Console.WriteLine("AcceptThread Start");
                IPAddress ip = IPAddress.Any;
                if (Config.IP != null) ip = Dns.GetHostEntry(Config.IP).AddressList[0];

                m_listener = new TcpListener(ip, Config.Port);
                m_listener.Start();
				while (true)
				{
Console.WriteLine("AcceptThread DONE");
					client = m_listener.AcceptSocket();
Console.WriteLine("AcceptThread AcceptSocket");
					if (client.Connected)
					{
						string Addr = client.RemoteEndPoint.ToString();
						int index = Addr.IndexOf(':');
						Addr = Addr.Substring(0, index );

                        Peer peer = new Peer(client, this, m_handler);
                        m_peerList.Add(peer);
					}
				}
			} catch (System.Net.Sockets.SocketException e) {
Console.WriteLine("AcceptThread SocketException");
                if (e.ErrorCode != 10004) {         // Ошибка не связана с остановкой объекта TCPListener
                    if (client != null)       // Закрытие сокета
						if (client.Connected)
							client.Close();
				}
			} catch {
Console.WriteLine("AcceptThread Exception");
                if (client != null)       // Закрытие сокета
                    if (client.Connected)
                        client.Close();
            }
		}
Exemplo n.º 2
0
        public void RemovePeer(Peer peer)
        {
            lock (m_peerList)
            {
                m_peerList.Remove(peer);
            }

        }