Esempio n. 1
0
        public void runThread()
        {
            try
            {
                logwrite.write("ISPSClient runThread", "\t ISPS Thread Start!!");

                String readLine = "";

                while (true)
                {
                    readLine = reader.ReadLine();
                    logwrite.write("ISPSReceiver runThread", readLine);
                }
            }
            catch (Exception e)
            {
                if (reader != null)
                {
                    reader.Close();
                    reader = null;
                }
                if (writeStream != null)
                {
                    writeStream.Close();
                    writeStream = null;
                }

                logwrite.write("ISPSReceiver runThread", e.ToString());
            }
            finally
            {
                ispsClient.sessionClose();



                // 사용자가 Disconnect 를 요청하지 않고 세션이 끊어진 경우 재접속 시도
                if (!ispsClient.getDisconnectReq())
                {
                    logwrite.write("ISPSReceiver runThread", "########## ISPS Session Closed !! ##########");

                    Event evt = new Event();
                    evt.setEvtCode(EVENT_TYPE.ON_DISCONNECTION);
                    evt.setEvtMsg("ISPS Session Disconnected");
                    evt.setCurIspsIP(ispsClient.getCurrentServerIP());
                    finesseObj.raiseEvent(evt);


                    if (ispsClient.reConnect() != ERRORCODE.SUCCESS)
                    {
                        // 서버 세션이 끊어지고, 재접속이 안될시 서버 프로세스가 올라올때까지 감지하는 스레드 시작한다.
                        ISocketSender ispsSender = new ISPSSender(logwrite, ispsClient);
                        ThreadStart   ts         = new ThreadStart(ispsSender.runThread);
                        Thread        thread     = new Thread(ts);
                        thread.Start();
                    }
                }
            }
        }
Esempio n. 2
0
        public void runThread()
        {
            ArrayList ipList = new ArrayList();

            ServerInfo serverInfo = ispsClient.getServerInfo();

            ipList = serverInfo.getIPList();
            int port = serverInfo.getPort();

            bool connectSuccess = false;

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

                    sock = new TcpClient();

                    var result = sock.BeginConnect(ip, port, null, null);

                    var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(CONNECTION.CONNECTION_TIMEOUT));

                    if (sock != null && sock.Connected)
                    {
                        connectSuccess = true;
                        logwrite.write("ISPS Sender", "Connection SUCCESS IP [" + ip + "] PORT [" + port + "]");
                        break;
                    }
                    else
                    {
                        logwrite.write("ISPS Sender", "Connection Fail IP [" + ip + "] PORT [" + port + "]");
                    }
                }
            }

            if (sock != null)
            {
                sock.Close();
            }

            ispsClient.reConnect();
        }