예제 #1
0
파일: Server.cs 프로젝트: WildGenie/uo-ext
        /// <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();
            }
		}
예제 #2
0
파일: Server.cs 프로젝트: WildGenie/uo-ext
        public void RemovePeer(Peer peer)
        {
            lock (m_peerList)
            {
                m_peerList.Remove(peer);
            }

        }