예제 #1
0
        public void runThread()
        {
            ArrayList ipList = new ArrayList();

            ServerInfo serverInfo = aemsClient.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("AEMS Sender", "Connection SUCCESS IP [" + ip + "] PORT [" + port + "]");
                        break;
                    }
                    else
                    {
                        logwrite.write("AEMS Sender", "Connection Fail IP [" + ip + "] PORT [" + port + "]");
                    }
                }
            }

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

            aemsClient.reConnect();
        }