Exemplo n.º 1
0
        public ListenerProxy(SocketTransponder transponder, ConnectSetting setting)
        {
            _transponder = transponder;
            _setting = setting;
            var localPoint = SocketSettings.GetHostAddress(_setting.Host, _setting.Port);
            var socketSetting = new SocketSettings(localPoint, setting.MaxPoolSize, setting.BufferSize, setting.Backlog);
            socketSetting.ContinuedTimeout = _setting.ConnectTimeout;
            socketSetting.EnableReceiveTimeout = _setting.EnableReceiveTimeout;
            socketSetting.ReceiveTimeout = _setting.ReceiveTimeout;

            _listener = new SocketListener(socketSetting);
            _listener.ConnectCompleted += OnConnectCompleted;
            _listener.ReceiveCompleted += _transponder.Receive;
            _listener.SocketSending += _transponder.OnSending;
            _listener.SocketClosing += OnSocketClosing;
            _listener.ReceiveTimeout += _transponder.OnReceiveTimeout;
            _transponder.SendCompleted += (address, data) =>
            {
                if (!_listener.PushSend(address, data))
                {
                    Console.WriteLine("发送到{0} {1}byte失败", address, data.Length);
                }
            };
            _transponder.CheckConnectedHandle += OnCheckConnected;
        }
Exemplo n.º 2
0
        public ListenerProxy(SocketTransponder transponder, ConnectSetting setting)
        {
            _transponder = transponder;
            _setting     = setting;
            var localPoint    = SocketSettings.GetHostAddress(_setting.Host, _setting.Port);
            var socketSetting = new SocketSettings(localPoint, setting.MaxPoolSize, setting.BufferSize, setting.Backlog);

            socketSetting.ContinuedTimeout     = _setting.ConnectTimeout;
            socketSetting.EnableReceiveTimeout = _setting.EnableReceiveTimeout;
            socketSetting.ReceiveTimeout       = _setting.ReceiveTimeout;

            _listener = new SocketListener(socketSetting);
            _listener.ConnectCompleted += OnConnectCompleted;
            _listener.ReceiveCompleted += _transponder.Receive;
            _listener.SocketSending    += _transponder.OnSending;
            _listener.SocketClosing    += OnSocketClosing;
            _listener.ReceiveTimeout   += _transponder.OnReceiveTimeout;
            _transponder.SendCompleted += (address, data) =>
            {
                if (!_listener.PushSend(address, data))
                {
                    Console.WriteLine("发送到{0} {1}byte失败", address, data.Length);
                }
            };
            _transponder.CheckConnectedHandle += OnCheckConnected;
        }