/// <summary> /// 处接接收到的应用层命令 /// </summary> /// <param name="gpsDataParser">GPS数据解析器</param> /// <param name="bufferSize">收发缓冲区大小</param> /// <param name="localAddress">本地IP地址</param> /// <param name="udpPort">UDP端口号</param> public SwitchAppLayerCmd(AnalyseBase gpsDataParser, int bufferSize, IPAddress localAddress, int udpPort) { try { //应答事件 GpsDataParser = gpsDataParser; //注册向应用层发送信息的事件 GpsDataParser.PostAckMsgHandlerEvent += new AnalyseBase.PostAckMsgHandler(GpsDataParser_PostAckMsgHandlerEvent); //向远端发送数据 GpsDataParser.SendDataEvent += new AnalyseBase.SendDataHandler(GpsDataParser_SendDataEvent); //将解析后的GPSCode与应用层IP加入列表 GpsDataParser.PostAppLayerAddressEvent += new AnalyseBase.PostAppLayerAddress(SetWebTable); CmdServer = new UdpServerBase(localAddress, udpPort, 5000, bufferSize); //注册接收网络消息事件 CmdServer.PostReceivedMsgEvent += new UdpServerBase.PostReceivedMsgHandler(SwitchEvent); WebTable = new Hashtable(); GpsDataParser.SendAnswerToWebEvent += new AnalyseBase.SendAnswerToWebHandler(SendAnswerToWeb); //GpsDataParser.PostSendHandlerAnswerEvent+=new AnalyseBase.PostSendAnswerHandler } catch (Exception ex) { Logger.Error(ex, null); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="gpsDataParser">数据解析器</param> /// <param name="ipAddress">向应用层公开的IP地址</param> /// <param name="udpPort">UDP监听端口号</param> /// <param name="maxSendPacket">发送数据包的最大长度</param> /// <param name="tcpserver"></param> /// <param name="bufferSize">收发缓冲区大小</param> /// <param name="useTcp">是否使用TCP通信</param> public UdpServer(AnalyseBase gpsDataParser,IPAddress ipAddress,int udpPort,int maxSendPacket,int bufferSize,bool useTcp,int udpPortByWeb) { try { GpsDataParser = gpsDataParser; localIPAddress = ipAddress; localPort = udpPort; webPort = udpPortByWeb; GpsDataParser.AddConnectionEvent += new AnalyseBase.AddConnectionHandler(gpsDataParse_AddConnectionEvent); GpsDataParser.DataSource = new IPEndPoint(ipAddress, udpPortByWeb); _UdpServerBase = new UdpServerBase(ipAddress, udpPort, maxSendPacket, bufferSize); //注册事件 _UdpServerBase.PostReceivedMsgEvent += new UdpServerBase.PostReceivedMsgHandler(_UdpServerBase_PostReceivedMsgEvent); _UdpServerBase.AddSocketToListEvent += new UdpServerBase.AddSocketToListHandler(AdddSocketToList); AsyncEventHashtable = new Hashtable(); CodeKeyHashtable = new Hashtable(); GatewayRoutingTable = new Dictionary<string, string>(); } catch (Exception ex) { Logger.Error(ex,null); } }
public UdpCommand(AnalyseBase gpsDataParser, IPAddress ipAddress, int udpPort, int bufferSize) { udpListener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); GpsDataParser = gpsDataParser; this.bufferSize = bufferSize; this.localPoint = new IPEndPoint(ipAddress, udpPort); }
/// <summary> /// 创建数据解析器对象 /// </summary> private void CreateDataParser(IGPSDataProcessor Storage) { try { switch (gpsType) { case "0001": Storage.CodePrefix = "0001"; GpsDataParserUDP = new XinAnDataParser("0001", Storage); break; case "0007": Storage.CodePrefix = "0007"; GpsDataParserTCP = new KaiYanDataParser(TransfersType.IsTcp, "0007", Storage); GpsDataParserUDP = new KaiYanDataParser(TransfersType.IsUdp, "0007", Storage); break; case "0009": Storage.CodePrefix = "0009"; GpsDataParserTCP = new YouWeiDataParser("0009", IsPrivateCar, Storage); break; case "0013": Storage.CodePrefix = "0013"; GpsDataParserTCP = new BoShiJieDataParser(TransfersType.IsTcp, "0013", Storage); GpsDataParserUDP = new BoShiJieDataParser(TransfersType.IsUdp, "0013", Storage); break; case "0014": Storage.CodePrefix = "0014"; if (ProtocolType == "UDP") GpsDataParserUDP = new DiBiaoDataParser(TransfersType.IsUdp, "0014", Storage); else if (ProtocolType == "TCP") GpsDataParserTCP = new DiBiaoDataParser(TransfersType.IsTcp, "0014", Storage); else if (ProtocolType == "TCP|UDP") { GpsDataParserUDP = new DiBiaoDataParser(TransfersType.IsUdp, "0014", Storage); GpsDataParserTCP = new DiBiaoDataParser(TransfersType.IsTcp, "0014", Storage); } break; case "0016": Storage.CodePrefix = "0016"; GpsDataParserTCP = new LongHanDataParser(TransfersType.IsTcp, "0016", Storage); GpsDataParserUDP = new LongHanDataParser(TransfersType.IsUdp, "0016", Storage); break; case "0019": //雅讯 Storage.CodePrefix = gpsType; GpsDataParserTCP = new YaXunDataParser(gpsType, Storage); break; case "0020": //0020部标 Storage.CodePrefix = gpsType; GpsDataParserTCP = new BuBiaoDataParser(gpsType, Storage); GpsDataParserTCP.Distributor = lstDistributor; break; case "0022": //永华 Storage.CodePrefix = gpsType; GpsDataParserTCP = new YongHuaDataParser(gpsType, Storage); break; case "0023": //康凯斯 Storage.CodePrefix = "0023"; GpsDataParserTCP = new KangKaiSiDataParser(gpsType, Storage); break; case "0033": // 联华盈科 Storage.CodePrefix = gpsType; GpsDataParserTCP = new LianHuaYingKeDataParser(gpsType, Storage); break; case "0099": Storage.CodePrefix = gpsType; GpsDataParserTCP = new MovoOneDataParser(gpsType, Storage); break; default: throw new Exception("非法的GPS类型,请查看配置"); } } catch (Exception ex) { Logger.Error(ex, null); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="gpsDataParser">数据解析器</param> public ProcessAppLayerCmd(AnalyseBase gpsDataParser) { GpsDataParser = gpsDataParser; }
public void AddParserInstance(string strType, AnalyseBase analysebase) { if (DataParserList.ContainsKey(strType)) { DataParserList.Remove(strType); } DataParserList.Add(strType, analysebase); }
public DistributeRawDataService(AnalyseBase analyseBase) { _base = analyseBase; _UdpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); }
public LogCollector(AnalyseBase analyseBase) { _base = analyseBase; }
/// <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); } }