/// <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);
            }
        }
Exemple #2
0
 public void StartConnectServer()
 {
     try
     {
         IPAddress = IPAddress.Parse(AppSetting.LocalIP);
         _UDPCommand = new UdpServerBase(IPAddress, AppSetting.LocalPORT, 5000, 1024);
         _UDPCommand.Start();
         _UDPCommand.PostReceivedMsgEvent += new UdpServerBase.PostReceivedMsgHandler(ReceiveDataEvent);
     }
     catch (Exception ex)
     {
         Logger.Error("CommandService.StartConnectServer:" + ex);
     }
 }
Exemple #3
0
 /// <summary>
 /// 处接接收到的应用层命令
 /// </summary>
 /// <param name="gpsDataParser">GPS数据解析器</param>
 /// <param name="bufferSize">收发缓冲区大小</param>
 /// <param name="localAddress">本地IP地址</param>
 /// <param name="udpPort">UDP端口号</param>
 public Switcher4WebApp(int bufferSize, IPAddress localAddress, int udpPort)
 {
     try
     {
         CmdServer = new UdpServerBase(localAddress, udpPort, 5000, bufferSize);
         //注册接收网络消息事件
         CmdServer.PostReceivedMsgEvent += new UdpServerBase.PostReceivedMsgHandler(SwitchEvent);
         WebTable = new Hashtable();
     }
     catch (Exception ex)
     {
         Logger.Error(ex, null);
     }
 }
        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"));
            udp = new UdpServerBase(System.Net.IPAddress.Parse(ip), port, maxcon, bufferSize);
            udp.PostReceivedMsgEvent += new UdpServerBase.PostReceivedMsgHandler(udp_PostReceivedMsgEvent);
            PES.Beehive.Logging.Logger.Info("初始化监听完成");

            base.Init();
            PES.Beehive.Logging.Logger.Info("初始数据化分发器完成");
        }
Exemple #5
0
        static void StartClient()
        {
            string filePath = Thread.GetDomain().BaseDirectory;
            FileInfo fileInfo = new FileInfo(filePath + "\\Config\\Environment\\log4net.config");
            log4net.Config.XmlConfigurator.Configure(fileInfo);

            string ip = ConfigHelper.GetConfig("localip");
            int port = int.Parse(ConfigHelper.GetConfig("localport"));
            int maxcon = int.Parse(ConfigHelper.GetConfig("MaxConnections"));
            int buffersize = int.Parse(ConfigHelper.GetConfig("BufferSize"));
            string protocolType = ConfigHelper.GetConfig("protocolType");

            if (protocolType == "udp")
            {
                udp = new UdpServerBase(System.Net.IPAddress.Parse(ip), port, maxcon, buffersize);
                udp.Start();
            }
            else if (protocolType == "tcp")
            {
                string businessIP = ConfigHelper.GetConfig("businessServerIP");
                int businessPort = int.Parse(ConfigHelper.GetConfig("businessserverport"));
                tcp = new System.Net.Sockets.TcpClient(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ip), port));
                tcp.SendBufferSize = buffersize;
                tcp.Connect(businessIP, businessPort);
            }

            System.Threading.Thread.Sleep(100);

            System.Threading.Thread t1 = new Thread(new ThreadStart(sFetachData));
            t1.Start();

            System.Threading.Thread t2 = new Thread(new ThreadStart(sCameraData));
            t2.Start();

            System.Threading.Thread t3 = new Thread(new ThreadStart(sLocatedData));
            t3.Start();

            System.Threading.Thread t4 = new Thread(new ThreadStart(sUnlessData));
            t4.Start();

            System.Threading.Thread t5 = new Thread(new ThreadStart(sAlarmData));
            t5.Start();
        }
Exemple #6
0
        /// <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);
            }
        }