static void Host() { IPAddress localIP = IPDetector.SelectIP(); try { Server = new Server(localIP); Hosted = true; Console.WriteLine("Server is hosted on \"" + Server.ServerUri + "\""); } catch (Exception e) { Console.WriteLine("Unable to host server on " + localIP.ToString()); } }
static void Connect() { IPAddress localIP = IPDetector.SelectIP(); IPAddress serverIP = null; bool entered = false; do { Console.WriteLine("Enter server IP-address"); try { serverIP = IPAddress.Parse(Console.ReadLine()); entered = true; } catch { Console.WriteLine("Input error. Wrong IP-address format"); } }while (!entered); int port = 0; entered = false; do { Console.WriteLine("Enter server port"); try { port = int.Parse(Console.ReadLine()); entered = true; } catch { Console.WriteLine("Input error. Port is integer number"); } }while (!entered); try { Worker = new Worker(localIP, serverIP, port); Connected = true; Console.WriteLine("Worker is hosted on \"" + Worker.LocalUri + "\""); Console.WriteLine("Worker is connected to server on \"" + Worker.ServerUri + "\""); } catch (Exception e) { Console.WriteLine("Unable to create worker on " + localIP.ToString() + " or connect to server on " + serverIP.ToString() + ":" + port.ToString()); } }