Exemplo n.º 1
0
 static async Task DoPingAndReconnect()
 {
     if (!await OtherCamCom.PingAdr(ConfigControl.savedIP.stringVal) || !sock.Connected)
     {
         OtherCamCom.LabelDisplay(false);
         TryConnect();
     }
 }
Exemplo n.º 2
0
        public static async Task <bool> TryConnect(bool showErrors = false, IPEndPoint customep = null) //Return true or false if Connect worked
        {
            bool result = true;                                                                         //needs to be on true

            try {
                if (connectingAlready)
                {
                    return(false);
                }

                connectingAlready = true;
                if (ConfigControl.savedIP.stringVal.Length == 0 ||
                    ConfigControl.savedPort.stringVal.Length == 0)
                {
                    result = false;
                }

                if (customep == null)
                {
                    customep = new IPEndPoint(IPAddress.Parse(ConfigControl.savedIP.stringVal),
                                              int.Parse(ConfigControl.savedPort.stringVal));
                }

                if (result)
                {
                    result = Connect(customep, showErrors);
                }
            } catch (Exception e) {
                if (showErrors)
                {
                    Tools.ShowPopup("Failed to initialize connection to camera!\nShow more?", "Connection Attempt Failed!"
                                    , e.ToString());
                }
                Console.WriteLine(e.ToString());

                result = false;
            }

            if (result && ConfigControl.legacyLayout.stringVal.ToUpper() == "LEGACY")
            {
                ConfigControl.savedIP.UpdateValue(MainForm.m.tB_Legacy_IP.Text);
                ConfigControl.savedPort.UpdateValue(MainForm.m.tB_Legacy_Port.Text);
            }

            connectingAlready = false;
            OtherCamCom.LabelDisplay(result);
            VideoSettings.UpdateControlFields();
            return(result);
        }
Exemplo n.º 3
0
        public static void Disconnect(bool showErrors = true)
        {
            try {
                if (sock == null || !MainForm.m.finishedLoading)
                {
                    return;
                }

                string oldAdr = null;
                try {
                    if (sock.RemoteEndPoint != null)
                    {
                        oldAdr = sock.RemoteEndPoint.ToString();
                    }
                } catch (Exception e) { }

                OtherCamCom.LabelDisplay(false);

                if (!ConfigControl.forceCamera.boolVal)
                {
                    InfoPanel.i.isCamera = false;
                }
                if (!sock.Connected)
                {
                    return;
                }
                sock.Shutdown(SocketShutdown.Both);
                if (oldAdr != null)
                {
                    MainForm.m.WriteToResponses("Disconnected from: " + oldAdr, true);
                }

                Console.WriteLine("disconnected");
            } catch (Exception e) {
                if (showErrors)
                {
                    Tools.ShowPopup("Disconnect error occurred!\nShow more?", "Error Occurred!", e.ToString());
                }
            }
        }