static void Setup() { _client = new SyncIOClient(TransportProtocol.IPv4, _packer); SetupPacketHandlers(); if (!_client.Connect(Host, Port)) { ConsoleExtentions.ErrorAndClose("Failed to connect to server."); } Console.WriteLine("Connected on port {0}. Waiting for handshake.", _client.EndPoint.Port); var success = _client.WaitForHandshake(); /* * The asynchronous way to get handshake would be subscribing * to the client.OnHandshake event. */ if (!success) { ConsoleExtentions.ErrorAndClose("Handshake failed."); } Console.WriteLine("Handshake success. Got ID: {0}", _client.ID); Console.WriteLine($"Enabling GZip compression..."); _client.SetCompression(new SyncIOCompressionGZip()); Console.WriteLine($"Enabling rijndael encryption using key {string.Join("", Key.Select(x => x.ToString("X2")))}"); _client.SetEncryption(new SyncIOEncryptionAes(Key, IV)); }
static void Main(string[] args) { Setup(); _client.Send(new ClientInfo(Environment.OSVersion.ToString(), Environment.UserName, Environment.MachineName, new Version("0.4.0"))); Console.WriteLine("Info set. You can now send messages."); var connected = true; _client.OnDisconnect += (s, err) => connected = false; //_client.Send(new DesktopScreenshot(ScreenCapture.GetDesktopScreenshot())); while (connected) { HandleCommands(connected, ConsoleExtentions.GetNonEmptyString("")); } ConsoleExtentions.ErrorAndClose("Lost connection to server"); }