Example #1
0
        public CSocket(IPEndPoint _endPoint, ScoketPool _pool, SocketPoolProfile config)
        {
            socketConfig = config;
            endpoint     = _endPoint;
            pool         = _pool;
            Socket _socket = new Socket(_endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, (int)config.SendTimeout.TotalMilliseconds);
            _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 24 * 3600 * 1000 /*one day*/);//(int)config.ReceiveTimeout.TotalMilliseconds);
            _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, !config.Nagle);
            _socket.Connect(_endPoint);
            socket           = _socket;
            this.inputStream = new BufferedStream(new NetworkStream(this.socket), config.BufferSize);
            Thread th = new Thread(delegate() {
                while (true)
                {
                    try
                    {
                        Receive();
                    }
                    catch (Exception ex)
                    {
                        logger.Notice(ex.Message);
                    }
                }
            });

            th.Start();
        }
Example #2
0
 /// <summary>
 /// relive server if this server is died
 /// </summary>
 private void Relive()
 {
     if (this.State == ServerState.Normal)
     {
         return;
     }
     lock (this)
     {
         if (this.State == ServerState.Normal)
         {
             return;
         }
         logger.Notice("this server is relive!host:" + Address);
         this.State = ServerState.Normal;;
     }
 }