public override void Init() { int bufferSize = 1024; string sBufferSize = ConfigHelper.GetConfig("BufferSize"); int.TryParse(sBufferSize, out bufferSize); int maxcon = int.Parse(ConfigHelper.GetConfig("MaxConnections")); int buffersize = int.Parse(ConfigHelper.GetConfig("BufferSize")); tcp = new TcpServerBase(System.Net.IPAddress.Parse(ip), port, maxcon, bufferSize); tcp.PostReceiveMsgEvent += new TcpServerBase.PostReceiveMsgHandler(tcp_PostReceiveMsgEvent); PES.Beehive.Logging.Logger.Info("初始化监听完成"); base.Init(); PES.Beehive.Logging.Logger.Info("初始数据化分发器完成"); }
/// <summary> /// 停止监听 /// </summary> public void Stop() { IsRunning = false; if (_TcpServerBase != null) { _TcpServerBase.Stop(); _TcpServerBase = null; } //释放缓存 //CacheProviderFactory.Default.ClearUp(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="gpsDataParser"></param> /// <param name="serverAddress">向应用层公开的IP地址,不是本地监听地址,它只是监听地址中的一个,监听是对本机所有IP监听</param> /// <param name="serverPort">监听端口号</param> /// <param name="numOfMaxConnections">最大连接数</param> /// <param name="unitBufferSize">收或发送缓冲区的大小</param> public TcpServer(AnalyseBase gpsDataParser,IPAddress serverAddress, int serverPort, int numOfMaxConnections, int unitBufferSize,int udpPortByWeb) { try { ipAddress = serverAddress; listenPort = serverPort; webPort = udpPortByWeb; _GpsDataParser = gpsDataParser; _GpsDataParser.IpEndPoint = new IPEndPoint(serverAddress, serverPort); _GpsDataParser.DataSource = new IPEndPoint(serverAddress, udpPortByWeb); //注册事件 _GpsDataParser.PostSendHandlerEvent += new AnalyseBase.PostSendHandler(GPSDataParse_PostSendHandlerEvent); _GpsDataParser.AddConnectionEvent += new AnalyseBase.AddConnectionHandler(gpsDataParse_AddConnectionEvent); //_GpsDataParser.CopyDataEvent += new AnalyseBase.CopyDataEventHeand(OnCopyDataEvent); //_GpsDataParser.ParsedDataEvent += new AnalyseBase.ParsedDataHandler(OnParsedDataEvent); _TcpServerBase = new TcpServerBase(serverAddress, serverPort, numOfMaxConnections, unitBufferSize); //客户端连接信息 _TcpServerBase.PostConnMsgEvent += new TcpServerBase.PostConnectionMessageHandler(OnPostConnMsgEvent); //收到数据事件 _TcpServerBase.PostReceiveMsgEvent += new TcpServerBase.PostReceiveMsgHandler(_TcpServerBase_PostReceiveMsgEvent); //移队连接的第一条数据事件 _TcpServerBase.RemoveDataOfConnEvent += new TcpServerBase.RemoveDataOfConnHandler(_TcpServerBase_RemoveDataOfConnEvent); //gpsCode与套接字哈希表的Key关系集合 _codeKeyHashtable = new Hashtable(); GatewayRoutingTable = new Dictionary<string, string>(); //Liuhuaihai add on 2012-5-23 //参考途鸽新网关进行的更改 TCPConnList.Instance().Servers.Add(this); } catch (Exception ex) { Logger.Error(ex, null); } }