Exemple #1
0
 public static void stop_tcp_client(ref RequestReplyTcpClient client, string name)
 {
     try
     {
         if (client != null)
         {
             client.Dispose();
             client = null;
             EzLogger.GlobalLogger.info("stop " + name + " success.");
         }
     }
     catch (System.Exception ex)
     {
         EzLogger.GlobalLogger.warning(string.Format("stop {0} failed: {1}{3}{2}{3}",
                                                     name, ex.Message, ex.StackTrace, Environment.NewLine));
     }
 }
Exemple #2
0
        public static Cmd tcp_client_send_and_response(RequestReplyTcpClient client, Cmd cmd, int timeout = 15000)
        {
            try
            {
                if (cmd == null || client == null || !client.Connected)
                {
                    return(null);
                }

                return(client.SendMessageAndWaitForResponse(cmd, timeout));
            }
            catch (System.Exception ex)
            {
                EzLogger.GlobalLogger.warning(string.Format("{0}{2}{1}{2}", ex.Message, ex.StackTrace, Environment.NewLine));

                return(null);
            }
        }
Exemple #3
0
        public static bool start_tcp_client(ref RequestReplyTcpClient client, string name,
                                            bool auto_hb, string sender, Action <AsyncTcpClient, Cmd> recv_func)
        {
            try
            {
                if (client == null)
                {
                    client = new RequestReplyTcpClient(auto_hb);
                    client.HeartBeatSender  = sender;
                    client.MessageReceived += recv_func;
                    EzLogger.GlobalLogger.info("start " + name + " success.");
                }
                return(true);
            }
            catch (System.Exception ex)
            {
                stop_tcp_client(ref client, name);

                EzLogger.GlobalLogger.warning(string.Format("start {0} failed: {1}{3}{2}{3}",
                                                            name, ex.Message, ex.StackTrace, Environment.NewLine));

                return(false);
            }
        }
Exemple #4
0
        public static Cmd tcp_client_send_and_response(RequestReplyTcpClient client, Cmd cmd, int timeout=15000)
        {
            try
            {
                if (cmd == null || client == null || !client.Connected)
                    return null;

                return client.SendMessageAndWaitForResponse(cmd, timeout);
            }
            catch (System.Exception ex)
            {
                EzLogger.GlobalLogger.warning(string.Format("{0}{2}{1}{2}", ex.Message, ex.StackTrace, Environment.NewLine));

                return null;
            }
        }
Exemple #5
0
 public static void stop_tcp_client(ref RequestReplyTcpClient client, string name)
 {
     try
     {
         if (client != null)
         {
             client.Dispose();
             client = null;
             EzLogger.GlobalLogger.info("stop " + name + " success.");
         }
     }
     catch (System.Exception ex)
     {
         EzLogger.GlobalLogger.warning(string.Format("stop {0} failed: {1}{3}{2}{3}",
             name, ex.Message, ex.StackTrace, Environment.NewLine));
     }
 }
Exemple #6
0
        public static bool start_tcp_client(ref RequestReplyTcpClient client, string name,
            bool auto_hb, string sender, Action<AsyncTcpClient, Cmd> recv_func)
        {
            try
            {
                if (client == null)
                {
                    client = new RequestReplyTcpClient(auto_hb);
                    client.HeartBeatSender = sender;
                    client.MessageReceived += recv_func;
                    EzLogger.GlobalLogger.info("start " + name + " success.");
                }
                return true;
            }
            catch (System.Exception ex)
            {
                stop_tcp_client(ref client, name);

                EzLogger.GlobalLogger.warning(string.Format("start {0} failed: {1}{3}{2}{3}",
                    name, ex.Message, ex.StackTrace, Environment.NewLine));

                return false;
            }
        }