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; }
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; }