示例#1
0
        void addconn(ClientToServerConnection that)
        {
            bool locked = false;

            try
            {
                Logger.Info("UMDServerConnect: Add Connection" + name);
                Monitor.TryEnter(lconns, 500, ref locked);
                if (locked)
                {
                    that.timer = new Timer(SendPing, that, 2000, 15000);
                    conns.Add(that);
                    //timer = new Timer(SendPing, this, 5000, 10000);
                }
                else
                {
                    throw new Exception("Deadlock adding a connection to a WinsysDB");
                }
            }
            catch (Exception e) { }
            finally { if (locked)
                      {
                          Monitor.Exit(lconns);
                      }
            }
        }
示例#2
0
        void rmconn(ClientToServerConnection that)
        {
            bool locked = false;

            try
            {
                Logger.Info($"UMDServerConnect: Remove Connection {name}");
                Monitor.TryEnter(lconns, 500, ref locked);
                if (locked)
                {
                    that.oclient = null;
                    that.timer.Dispose();
                    conns.Remove(that);
                }
                else
                {
                    throw new Exception($"Deadlock removing a connection to {name}");
                }
            }
            catch (Exception e) { }
            finally { if (locked)
                      {
                          Monitor.Exit(lconns);
                      }
            }
        }
示例#3
0
        private static void SendPing(object state)
        {
            ClientToServerConnection conn = (ClientToServerConnection)state;

            Logger.Debug($"Manager API sending Ping to {conn.name}");

            if (conn.bRunning && conns.Contains(conn))
            {
                if (conn.oclient == null)
                {
                    conn.bRunning = false;
                }
                else
                {
                    WebsocketClient ws = ((MobileDeliveryClient.WebsocketClient)conn.oclient);
                    if (ws.IsRunning)
                    {
                        Task snd = conn.oclient.Send(new Command()
                        {
                            command = eCommand.Ping
                        }.ToArray());

                        if (snd.Status == TaskStatus.Faulted && !conn.recon)
                        {
                            conn.recon = true;
                            Logger.Info($"Server Disconnected, reconnect! {conn.name}");
                            // Disconnect();
                            Thread.Sleep(600);
                            if (!conn.bRunning)
                            {
                                conn.StartAsync();
                            }
                            Logger.Info($"Server Disconnected Done reconnecting! {conn.name}");
                            conn.recon = false;
                        }
                    }
                    else if (!conn.recon)
                    {
                        conn.recon = true;
                        Logger.Info($"Server Disconnected, reconnect! {conn.name}");
                        conn.StartAsync();
                        Thread.Sleep(600);
                        Logger.Info($"Server Disconnected Done reconnecting! {conn.name}");
                        conn.recon = false;
                    }
                }
            }
            else
            {
                conn.bRunning = false;
            }
        }