コード例 #1
0
ファイル: ListenerProxy.cs プロジェクト: rongxiong/Scut
        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;
        }
コード例 #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;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: rongxiong/Scut
 private static ConnectSetting LoadSetting(string preKey)
 {
     var setting = new ConnectSetting();
     setting.Host = ConfigUtils.GetSetting(preKey + ".Host");
     setting.Port = ConfigUtils.GetSetting(preKey + ".Port").ToInt();
     setting.Backlog = ConfigUtils.GetSetting(preKey + ".Backlog", "10").ToInt();
     setting.ConnectTimeout = ConfigUtils.GetSetting(preKey + ".ContinuedTimeout", "60").ToInt();
     setting.BufferSize = ConfigUtils.GetSetting(preKey + ".BufferSize", "1024").ToInt();
     setting.MinPoolSize = ConfigUtils.GetSetting(preKey + ".MinConnectNum", "10").ToInt();
     setting.MaxPoolSize = ConfigUtils.GetSetting(preKey + ".MaxConnectNum", "1000").ToInt();
     setting.EnableReceiveTimeout = ConfigUtils.GetSetting(preKey + ".EnableReceiveTimeout", "false").ToBool();
     setting.ReceiveTimeout = ConfigUtils.GetSetting(preKey + ".ReceiveTimeout", "30000").ToInt();
     return setting;
 }