Esempio n. 1
0
        /// <summary>
        /// Handles the wait loop for accepting input from the socket
        /// </summary>
        /// <param name="worker">the function that actually takes in a full message from the socker</param>
        private async void ReconnectLoop(double suspendMultiplier = 1)
        {
            if (MyClient != null && MyClient.IsAlive || suspendMultiplier > ConfigSettings.SuspendMultiplierMaximum)
            {
                return;
            }

            DoLog("Gossip Server Reconnect Loop Pulse x" + suspendMultiplier.ToString());

            try
            {
                if (MyClient == null)
                {
                    GetNewSocket();
                }

                MyClient.Connect();

                if (MyClient.ReadyState == WebSocketState.Open)
                {
                    DoLog("Gossip Server Reconnect Loop Successful.");
                    return;
                }

                await Task.Delay(Convert.ToInt32(10000 * suspendMultiplier));

                ReconnectLoop(suspendMultiplier * ConfigSettings.SuspendMultiplier);
            }
            catch (Exception ex)
            {
                DoLog(ex);
            }
        }
Esempio n. 2
0
        private async Task <INetClient> ConnectClient()
        {
            var client = new MyClient("127.0.0.1", 4444, 512);

            client.Connect();
            await this.DelayAction(5, 100, () => !client.IsConnected);

            return(client);
        }
Esempio n. 3
0
 static void Main(string[] args)
 {
     using (MyClient client = new MyClient())
     {
         // Handle the parameters from user input.
         string ip   = null;
         int    port = -1;
         if (args.Length < 2)
         {
             WriteLine("Please enter IP and port.");
         }
         foreach (var item in args)
         {
             if (item.Substring(0, 5) == "-port")
             {
                 port = Convert.ToInt32(item.Split('=')[1]);
             }
             else if (item.Substring(0, 3) == "-ip")
             {
                 ip = item.Split("=")[1];
             }
         }
         if (string.IsNullOrEmpty(ip) || port == -1)
         {
             WriteLine("Invalid parameters!");
             return;
         }
         // Connect this client to the server.
         client.Connect(IPAddress.Parse(ip), port);
         client.NewMessageEvent += Client_NewMessageEvent;
         string message = ReadLine();
         // Handle user input. The connection will be dropped when the
         // input is null or empty string.
         while (!string.IsNullOrEmpty(message))
         {
             client.SendString(message);  // Send the string to the server.
             message = ReadLine();        // Get user input.
         }
         client.SendString(string.Empty); // Send empty string to the server, which
         // tells the server to drop the connection.
     }
     WriteLine("Press any key to exit...");
     ReadKey();
 }
Esempio n. 4
0
        public BrowserForm()
        {
            this.FormClosing += BrowserForm_FormClosing;
            this.Load        += BrowserForm_Load;

            InitializeComponent();

            Text        = "Link Extractor";
            WindowState = FormWindowState.Maximized;

            InitializeCef();


            new Thread(() =>
            {
                client.Connect();
            }).Start();

            //MainWindow wpfwindow = new MainWindow();
            //ElementHost.EnableModelessKeyboardInterop(wpfwindow);
            //wpfwindow.Show();
        }
Esempio n. 5
0
        /// <summary>
        /// Registers this for a service on a port
        /// </summary>
        /// <param name="portNumber">the port it is listening on</param>
        public async void Launch()
        {
            if (string.IsNullOrWhiteSpace(ConfigSettings.ClientId) || string.IsNullOrWhiteSpace(ConfigSettings.ClientSecret))
            {
                DoLog("No credentials to connect to Gossip with, ending.");
                return;
            }

            try
            {
                //Connect to the gossip service
                GetNewSocket();

                MyClient.Connect();

                if (MyClient.ReadyState != WebSocketState.Open)
                {
                    throw new TimeoutException("Gossip Server unresponsive on open. Starting reconnect loop.");
                }

                await Task.Delay(1);
            }
            catch (TimeoutException tex)
            {
                DoLog(tex);
                ReconnectLoop(60);
            }
            catch (System.Net.Sockets.SocketException sex)
            {
                DoLog(sex); //Dont retry on this
            }
            catch (Exception ex)
            {
                DoLog(ex);
                ReconnectLoop(10);
            }
        }