Example #1
0
        private static void ExecConnect(string[] args)
        {
            if (client.IsConnected)
            {
                Console.WriteLine("Client is already connected");
                return;
            }

            if (args.Length != 2)
            {
                Console.WriteLine("Invalid args");
                return;
            }

            string[] parts = args[1].Split(':');
            if (parts.Length != 2)
            {
                Console.WriteLine("Invalid args");
                return;
            }

            try
            {
                client.Connect(parts[0], int.Parse(parts[1]), client.ClientName);
            }catch (Exception ex)
            {
                Console.WriteLine("Could not connect: " + ex.Message);
            }
        }
Example #2
0
 private void HandleConnectMessage(NetIpcConnectMessage message)
 {
     if (!client.IsConnected)
     {
         client.Connect(message.Address);
     }
 }
Example #3
0
        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();
            }
        }
Example #4
0
        public static void Run()
        {
            Console.Title = "Inputshare client (Inactive)";
            Console.Clear();

            client = new ISClient(InputshareLibWindows.WindowsDependencies.GetClientDependencies());
            client.ActiveClientChanged += Client_ActiveClientChanged;
            client.ClipboardDataCopied += Client_ClipboardDataCopied;
            client.Connected           += Client_Connected;
            client.ConnectionFailed    += Client_ConnectionFailed;
            client.ConnectionError     += Client_ConnectionError;
            client.Disconnected        += Client_Disconnected;
            string     clientName = "";
            IPEndPoint address    = null;

            Console.WriteLine("Enter client name (leave blank to use machine name)");
            clientName = Console.ReadLine();
            if (string.IsNullOrEmpty(clientName))
            {
                clientName = Environment.MachineName;
            }


            while (address == null)
            {
                Console.Clear();
                Console.WriteLine("Enter server address:port");
                Console.Write("Connect to: ");
                string addr = Console.ReadLine();

                if (string.IsNullOrEmpty(addr))
                {
                    addr = "192.168.0.7:4441";
                }

                string[] parts = addr.Split(':');
                if (parts.Length != 2)
                {
                    continue;
                }

                if (!IPAddress.TryParse(parts[0], out IPAddress ip))
                {
                    continue;
                }

                if (!int.TryParse(parts[1], out int p))
                {
                    continue;
                }

                if (p < 1 || p > 65535)
                {
                    continue;
                }

                address = new IPEndPoint(ip, p);
            }


            Console.WriteLine("Available commands (non case sensitive):");
            Console.WriteLine("For details on a command, type help followed by the command\n");

            Console.WriteLine("'Connect address:port' - Connects to a server");
            Console.WriteLine("'Disconnect' - Disconnects from server");
            Console.WriteLine();

            client.Connect(address.Address.ToString(), address.Port, clientName);



            while (true)
            {
                if (client.IsConnected)
                {
                    Console.Write("{0}@{1}:", client.ClientName, client.ServerAddress);
                }
                else
                {
                    Console.Write("Inputshare client: ");
                }

                string cmd = Console.ReadLine();
                ExecCmd(cmd);
            }


            Thread.Sleep(1000);
            Console.Write(".");
            Thread.Sleep(1000);
            Console.Write(".");
            Thread.Sleep(1000);
            Console.Write(".");
            Thread.Sleep(1000);
        }