public void SendComplexMessage(string message) { try { // Create the message to send ComplexMessage msg = new ComplexMessage { UniqueID = Guid.NewGuid(), Time = DateTimeOffset.Now, Message = message }; // Serialize the message to a binary array byte[] binaryMessage = SerializationHelper.Serialize(msg); // Send the message; the state is used by ClientSocket_WriteCompleted to display an output to the log string description = "<complex message: " + msg.UniqueID + ">"; ClientSocket.WriteAsync(binaryMessage, description); Console.WriteLine("Sending message " + description); } catch (Exception ex) { ResetSocket(); Console.WriteLine("Error sending message to socket: [" + ex.GetType().Name + "] " + ex.Message); } finally { RefreshDisplay(); } }
public void SendComplexMessage(KeyValuePair<SimpleServerChildTcpSocket, ChildSocketState> childSocket, string message) { // This function sends a complex message to all connected clients ComplexMessage msg = new ComplexMessage(); msg.UniqueID = Guid.NewGuid(); msg.Time = DateTimeOffset.Now; msg.Message = message; string description = "<complex message: " + msg.UniqueID + ">"; // Serialize it to a binary array byte[] binaryObject = SerializationHelper.Serialize(msg); SendSerializedMessage(childSocket, binaryObject, description); }