Example #1
0
        public void TCP_Connect(string ipAddress, int port)
        {
            if (msgClient == null || !msgClient.IsConnected())
            {
                msgClient = new MsgrClientManager(ipAddress, port, "tcp_cli");
            }
            else
            {
                AppendConsoleMsg(">[SERVER_CONNECT]Socket Already Inited.");
            }

            msgClient.SocStatusChanged += SocStatusChanged;

            if (!msgClient.IsConnected())
            {
                msgClient.Connect();
            }
            else
            {
                AppendConsoleMsg(">[SERVER_CONNECT]Server Already Connected.");
            }


            if (msgClient.IsConnected())
            {
                AppendConsoleMsg(">[SERVER_CONNECT]Server Connected.");
            }
            else
            {
                AppendConsoleMsg(">[SERVER_CONNECT]Server Not Connected.");
            }
        }
Example #2
0
        public void TCP_Connect(string ipAddress, int port)
        {
            if (msgClient == null || !msgClient.IsConnected())
                msgClient = new MsgrClientManager(ipAddress, port, "tcp_cli");
            else
                AppendConsoleMsg(">[SERVER_CONNECT]Socket Already Inited.");

            msgClient.SocStatusChanged += SocStatusChanged;

            if (!msgClient.IsConnected())
                msgClient.Connect();
            else
                AppendConsoleMsg(">[SERVER_CONNECT]Server Already Connected.");

            if (msgClient.IsConnected())
            {
                AppendConsoleMsg(">[SERVER_CONNECT]Server Connected.");
            }
            else
            {
                AppendConsoleMsg(">[SERVER_CONNECT]Server Not Connected.");
            }
        }
        public bool StartService()
        {
            bool result = false;

            try
            {
                Logger.info("StartService() 시작");
                //서버 IP구하기
                serverIP = ConfigHelper.ServerIp;
                if (serverIP.ToLower().Equals("localhost") ||
                    serverIP.ToLower().Equals("127.0.0.1"))
                {
                    //serverIP = "127.0.0.1";
                    IPHostEntry host = Dns.Resolve(Dns.GetHostName());
                    serverIP = host.AddressList[0].ToString();
                }

                if (msgClient == null || !msgClient.IsConnected())
                {
                    msgClient = new MsgrClientManager(serverIP, ConfigHelper.SocketPortMsgr, ConfigHelper.TryId);
                    msgClient.TCPStatusChanged     += ProcessOnTCPStatusChanged;
                    msgClient.ManagerStatusChanged += ProcessOnManagerStatusChanged;
                    msgClient.TCPMsgReceived       += ProcessOnMessageReceived;
                    msgClient.FTPSendingProgressed += ProcessOnFTPSendingProgressed;
                    msgClient.FTPSendingFinished   += ProcessOnFTPSendingFinished;
                    msgClient.FTPSendingCanceled   += ProcessOnFTPSendingCanceled;
                    msgClient.FTPSendingFailed     += ProcessOnFTPSendingFailed;
                    msgClient.TCPConnectionError   += ProcessOnTCPConnectionError;
                    msgClient.FTPConnectionError   += ProcessOnFTPConnectionError;
                    msgClient.FTPSendingNotified   += ProcessOnFTPSendingNotified;
                    msgClient.FTPSendingAccepted   += ProcessOnFTPSendingAccepted;
                    msgClient.FTPSendingRejected   += ProcessOnFTPSendingRejected;
                }
                else
                {
                    Logger.info("[SERVER_CONNECT]Socket Already Inited.");
                }

                if (!msgClient.IsConnected())
                {
                    msgClient.Connect();
                }
                else
                {
                    Logger.info("[SERVER_CONNECT]Server Already Connected.");
                }

                if (msgClient.IsConnected())
                {
                    Logger.info(string.Format("[SERVER_CONNECT]서버 접속.[{0}:{1}]", serverIP, ConfigHelper.SocketPortMsgr));
                }
                else
                {
                    throw new Exception(string.Format("[SERVER_CONNECT]서버 접속실패.[{0}:{1}]", serverIP, ConfigHelper.SocketPortMsgr));
                }

                Thread thMsgReader = new Thread(new ThreadStart(msgClient.ReceiveMessage));
                thMsgReader.Start();
                result = true;
            }
            catch (Exception ex)
            {
                Logger.error("connection.StartService 실행에러 : " + ex.ToString());
            }
            return(result);
        }