예제 #1
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);
     }
 }
예제 #2
0
파일: Program.cs 프로젝트: hhahh2011/CH.Gps
        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();
        }