Beispiel #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();
 }
Beispiel #2
0
 public ScoketPool(Server server, SocketPoolProfile config)
 {
     _Server          = server;
     endPoint         = new IPEndPoint(IPAddress.Parse(server.Address), server.Port);
     socketPoolConfig = config;
     pool             = new ConnPool(config.ShrinkInterval, config.MinPoolSize);
 }
Beispiel #3
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();
        }