public static void Run() { Console.Clear(); int port = 0; do { Console.WriteLine("Enter port to start server: (blank for 4441)"); string pStr = Console.ReadLine(); if (string.IsNullOrEmpty(pStr)) { port = 4441; } else { int.TryParse(pStr, out port); } Console.Clear(); } while (port < 1 || port > 65535); Console.Clear(); server = new ISServer(WindowsDependencies.GetServerDependencies()); server.ClientConnected += Server_ClientConnected; server.ClientDisconnected += Server_ClientDisconnected; server.InputClientSwitched += Server_InputClientSwitched; server.Started += Server_Started; server.Stopped += Server_Stopped; try { server.Start(port); } catch (Exception ex) { Console.WriteLine("Failed to start server: " + ex.Message); } PrintHelp(); Thread.Sleep(250); while (server.Running) { ExecCmd(Console.ReadLine()); } Thread.Sleep(1000); Console.Write("."); Thread.Sleep(1000); Console.Write("."); Thread.Sleep(1000); Console.Write("."); Thread.Sleep(1000); return; }
private void LoadAndStart() { try { clientInstance = new ISClient(); clientInstance.Start(new StartOptions(new System.Collections.Generic.List <string>(new string[] { "Verbose" })), WindowsDependencies.GetServiceDependencies(spMainHandle, spClipboardHandle)); clientInstance.ConnectionError += ClientInstance_ConnectionError; clientInstance.ConnectionFailed += ClientInstance_ConnectionFailed; clientInstance.Connected += ClientInstance_Connected; clientInstance.SasRequested += (object a, EventArgs b) => InputshareLibWindows.Native.Sas.SendSAS(false); clientInstance.Disconnected += ClientInstance_Disconnected; clientInstance.AutoReconnect = true; try { appHost = new NetIpcHost(clientInstance, "App connection"); }catch (Exception ex) { ISLogger.Write("Failed to create NetIPC host: " + ex.Message); } if (ConfigFile.TryReadProperty(ServiceConfigProperties.LastConnectedAddress, out string addrStr)) { if (IPEndPoint.TryParse(addrStr, out IPEndPoint addr)) { clientInstance.Connect(addr); } else { ISLogger.Write("Invalid address in config"); } } ISLogger.Write("Service started..."); } catch (Exception ex) { ISLogger.Write("LAUNCH ERROR - " + ex.Message); ISLogger.Write(ex.StackTrace); Stop(); } }