public void Start() { _udpClient.BeginReceive(UdpRecieveLoop, null); _tcpListener.Start(); _tcpListener.BeginAcceptSocket(TcpAcceptLoop, null); using (var mem = new MemoryStream()) { var wrt = new BinaryWriter(mem); wrt.Write(true); //New client added wrt.Write(PublicKey.Length); wrt.Write(PublicKey); //This is not necessary //Length is a fixed 16 bytes //wrt.Write(_broadcastGuid.ToByteArray()); mem.Position = 0; GlobalHelpers.BroadcastPacket(mem.ToArray(), NetworkPort); } }
public void Dispose() { try { using (var mem = new MemoryStream()) { var wrt = new BinaryWriter(mem); wrt.Write(false); //Client is leaving. wrt.Write(PublicKey.Length); wrt.Write(PublicKey); mem.Position = 0; GlobalHelpers.BroadcastPacket(mem.ToArray(), NetworkPort); } } catch { //Ignore this, we're dying anyway. } _udpClient?.Close(); _tcpListener?.Stop(); }