void CreateClient() { // Create the client var client = new SimplSocketClient(); // Make the client connect automatically client.AutoConnect(); // Wait until the connection is actually made client.WaitForConnection(); // Create a byte array to send var arrayToSend1 = new byte[1000]; // Send it client.Send(arrayToSend1); // Get a byte array from the memory pool var arrayToSend2 = PooledMessage.Rent(1000); client.Send(arrayToSend2); // We will not dispose the message directly, since it may still need to be send // Instead we use the ReturnAfterSend, which will return the message to the pool after sending arrayToSend2.ReturnAfterSend(); }
void CreateClient() { // Create the client var client = new SimplSocketClient(); // Make the client connect automatically client.AutoConnect(); // Wait until the connection is actually made client.WaitForConnection(); // Create a byte array to send var messageToSend = new byte[1000]; // Send it Console.WriteLine("Client will send message and wait for reply"); var receivedMessage = client.SendReceive(messageToSend); if (receivedMessage == null) { Console.WriteLine("Client received no answer"); } else { Console.WriteLine($"Client received answer of {receivedMessage.Length} bytes"); // Return message to pool receivedMessage.Return(); } }
void CreateClient() { // Create the client var client = new SimplSocketClient(); // Make the client connect automatically client.AutoConnect(); // Create a callback for received data client.MessageReceived += (s, e) => { // Get the message var receivedMessage = e.ReceivedMessage; Console.WriteLine($"Client received message of {receivedMessage.Length} bytes"); // Return the message to the pool receivedMessage.Return(); }; }
public void AutoConnect(string serverName = "SimplMessageServer") { _simplSocketClient.AutoConnect(serverName); }