Ejemplo n.º 1
0
        public int monConnect(string mon_A_IP, string mon_B_IP, int port)
        {
            disconnectReq = false;

            logwrite.write("monConnect", "** call monConnect(" + mon_A_IP + " , " + mon_B_IP + " , " + port + ")");

            client = new AEMSClient(logwrite, this);

            ipList = new ArrayList();
            ipList.Add(mon_A_IP);
            ipList.Add(mon_B_IP);
            this.port = port;

            isConnected = false;

            for (int i = 0; i < ipList.Count; i++)
            {
                string ip = (string)ipList[i];

                logwrite.write("monConnect", "TRY TO CONNECT " + ip + " , " + port);
                if (client.connect(ip, port) == ERRORCODE.SUCCESS)
                {
                    logwrite.write("monConnect", "CONNECT SUCCESS!!");
                    currentConnectedIP = ip;
                    isConnected        = true;

                    client.startMonitoring();

                    JsonHandler jsonHandler = new JsonHandler();
                    jsonHandler.setType("M07");
                    jsonHandler.setCmd("M07");
                    string jsonData = jsonHandler.getJsonData();

                    jsonData = jsonData.Replace("type", "@type");

                    client.send(jsonData);

                    jsonHandler.setType("M08");
                    jsonHandler.setCmd("M08");
                    jsonData = jsonHandler.getJsonData();

                    jsonData = jsonData.Replace("type", "@type");

                    client.send(jsonData);

                    break;
                }
                else
                {
                    logwrite.write("monConnect", "CONNECT FAIL !!");
                    isConnected = false;
                }
            }

            return(isConnected ? ERRORCODE.SUCCESS : ERRORCODE.FAIL);
        }
Ejemplo n.º 2
0
        public void runThread()
        {
            try
            {
                string line = "";

                while ((line = reader.ReadLine()) != null)
                {
                    logwrite.write("runThread", line);

                    if (line.Length == 0)
                    {
                        continue;
                    }

                    MonitoringVO monVO = jsonHandler.recvJson(line);

                    if (monVO != null)
                    {
                        switch (monVO.getCmd())
                        {
                        case "M07":
                            logwrite.write("runThread", "M07 data -> " + monVO.getStrResult());
                            setSkillInfo(monVO.getStrResult());
                            break;

                        case "M08":
                            logwrite.write("runThread", "M08 data -> " + monVO.getStrResult());
                            break;

                        default:
                            break;
                        }
                    }


                    monObj.GetEventOnMon1(line);
                }
            }
            catch (Exception e)
            {
                logwrite.write("runThread", e.ToString());
                if (!monObj.disconnectReq)
                {
                    // 접속이 끊어지면 접속 재시도
                    monObj.monReConnect();
                }
            }
        }
Ejemplo n.º 3
0
 public void runThread()
 {
     try
     {
         while (true)
         {
             Thread.Sleep(1000);
             if (monObj.monReConnect() == ERRORCODE.SUCCESS)
             {
                 logwrite.write("MonSender renThread", "Connection Success !!");
                 break;
             }
             else
             {
                 logwrite.write("MonSender renThread", "Connection Fail !! Retry");
             }
         }
     }
     catch (Exception e)
     {
         logwrite.write("MonSender renThread", e.ToString());
     }
 }
Ejemplo n.º 4
0
        public int connect(string ip, int port)
        {
            try
            {
                sock = new TcpClient();

                logwrite.write("connect", "\t Try to Connect " + ip + " , " + port);

                IAsyncResult result  = sock.BeginConnect(ip, port, null, null);
                var          success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(3000), true);

                if (success)
                {
                    logwrite.write("connect", "\t Connection Success !!" + ip + " , " + port);

                    writeStream = sock.GetStream();
                    writer      = new StreamWriter(writeStream);

                    //Encoding encode = System.Text.Encoding.GetEncoding("ANSI");
                    //reader = new StreamReader(writeStream, encode);
                    //reader = new StreamReader(writeStream);
                }
                else
                {
                    logwrite.write("connect", "\t Connection Fail !!" + ip + " , " + port);
                    return(ERRORCODE.SOCKET_CONNECTION_FAIL);
                }
            }
            catch (Exception e)
            {
                logwrite.write("connect", e.ToString());
                if (sock != null)
                {
                    sock.Close();
                    sock = null;
                }
                return(ERRORCODE.SOCKET_CONNECTION_FAIL);
            }

            return(ERRORCODE.SUCCESS);
        }