public bool SendMessage(Message msg) { try { byte[] buffer = Encoding.Unicode.GetBytes(msg.ToString()); streamToServer.Write(buffer, 0, buffer.Length); return true; } catch { return false; } }
public bool SendMessage(Message msg, NetworkStream streamToClient) { string msgString = msg.ToString(); byte[] buffer = Encoding.Unicode.GetBytes(msgString); try { streamToClient.Write(buffer, 0, buffer.Length); return true; } catch { return false; throw; } }