Ejemplo n.º 1
0
        bool ISocket.StartListening(SocketConnectionAccepted callback)
        {
            IPAddress any = IPAddress.Any;
            string    ipString;

            if (Program.LaunchParameters.TryGetValue("-ip", out ipString) && !IPAddress.TryParse(ipString, out any))
            {
                any = IPAddress.Any;
            }
            this._isListening      = true;
            this._listenerCallback = callback;
            if (this._listener == null)
            {
                this._listener = new TcpListener(any, Netplay.ListenPort);
            }
            try
            {
                this._listener.Start();
            }
            catch (Exception)
            {
                return(false);
            }

            _limiter = new Limiter(_config);

            new Thread(this.ListenLoop).Start();
            return(true);
        }
Ejemplo n.º 2
0
        public TcpSocket(Config config, Limiter limiter, TcpClient tcpClient)
        {
            _config                  = config;
            _limiter                 = limiter;
            this._connection         = tcpClient;
            this._connection.NoDelay = true;
            IPEndPoint iPEndPoint = (IPEndPoint)tcpClient.Client.RemoteEndPoint;

            this._remoteAddress = new TcpAddress(iPEndPoint.Address, iPEndPoint.Port);
            _ip = iPEndPoint.Address.ToString();
        }