/// <summary>Close this connection for good. This class should not be used again after calling this.</summary> protected override void Dispose(bool disposing) { if (disposing && _udp != null) { if (Loopback != null) { var port = (ushort)((IPEndPoint)_udp.Client.LocalEndPoint).Port; LoopbacksByPort.Remove(port); BoundPorts[port] = false; } _udp.Close(); _udp = null; } }
/// <summary>Use this to implement actual sending of the given data to the given endpoint.</summary> /// <param name="message">the data to send/</param> /// <param name="endPoint">the end point to send it to.</param> protected override void HandleSend(byte[] message, IPEndPoint endPoint) { // Are we delivering locally? if (IPAddress.IsLoopback(endPoint.Address) && LoopbacksByPort.ContainsKey((ushort)endPoint.Port)) { // Yes, inject directly. LoopbacksByPort[(ushort)endPoint.Port].HandleReceive(message, Loopback); } else { // No, send via the network. _udp.Send(message, message.Length, endPoint); } }