/// <summary> /// Dispose per the IDisposable pattern /// </summary> public void Dispose() { GC.SuppressFinalize(this); if (!disposed) { disposed = true; if (sock != null) { // if we are using a reflector, send a tear-down message if (!multicastEP.Equals(nextHopEP)) { try { if (joiner != null) { joiner.Terminate(); } // send a LEAVE message; this might get lost, but that doesn't matter // because the reflector wil time out. UdpSender sender = new UdpSender(nextHopEP, 64); UdpReflectorMessage message = new UdpReflectorMessage(UdpReflectorMessageType.LEAVE, multicastEP); sender.Send(message.ToBufferChunk()); sender.Dispose(); } catch (Exception) { } } LstSocks.Socket.ReleaseSharedSocket(nextHopEP, sock); sock = null; } } }
/// <summary> /// Send UDP join messages to the reflector. There is no acknoweledgement, so we send /// a series of these messages, pausing briefly in between. /// /// A bit of ugliness: the joiner works over both C#'s built in socket, as well as CXP's /// UDPSender. If the class was initialized without a Socket, then we create a locale UdpSender. /// This is necessary because the client uses UdpSender, whereas the reflector uses raw sockets. /// </summary> private void SendJoinMessages() { Debug.Assert(reflectorEP != null); Debug.Assert(multicastEP != null); UdpSender sender = null; try { sender = new UdpSender(this.reflectorEP, 64); sender.DisableLoopback(); while (alive) { UdpReflectorMessage rjm = new UdpReflectorMessage(UdpReflectorMessageType.JOIN, multicastEP); BufferChunk bufferChunk = rjm.ToBufferChunk(); // UdpSender, as used by CXPClient sender.Send(bufferChunk); Thread.Sleep(JOIN_MESSAGE_DELAY); } } catch { } finally { if (sender != null) sender.Dispose(); } }
/// <summary> /// Send UDP join messages to the reflector. There is no acknoweledgement, so we send /// a series of these messages, pausing briefly in between. /// /// A bit of ugliness: the joiner works over both C#'s built in socket, as well as CXP's /// UDPSender. If the class was initialized without a Socket, then we create a locale UdpSender. /// This is necessary because the client uses UdpSender, whereas the reflector uses raw sockets. /// </summary> private void SendJoinMessages() { Debug.Assert(reflectorEP != null); Debug.Assert(multicastEP != null); UdpSender sender = null; try { sender = new UdpSender(this.reflectorEP, 64); sender.DisableLoopback(); while (alive) { UdpReflectorMessage rjm = new UdpReflectorMessage(UdpReflectorMessageType.JOIN, multicastEP); BufferChunk bufferChunk = rjm.ToBufferChunk(); // UdpSender, as used by CXPClient sender.Send(bufferChunk); Thread.Sleep(JOIN_MESSAGE_DELAY); } } catch { } finally { if (sender != null) { sender.Dispose(); } } }
/// <summary> /// Dispose per the IDisposable pattern /// </summary> public void Dispose() { GC.SuppressFinalize(this); if(!disposed) { disposed = true; if (sock != null) { // if we are using a reflector, send a tear-down message if (!multicastEP.Equals(nextHopEP)) { try { if (joiner != null) joiner.Terminate(); // send a LEAVE message; this might get lost, but that doesn't matter // because the reflector wil time out. UdpSender sender = new UdpSender(nextHopEP, 64); UdpReflectorMessage message = new UdpReflectorMessage(UdpReflectorMessageType.LEAVE, multicastEP); sender.Send(message.ToBufferChunk()); sender.Dispose(); } catch (Exception) { } } LstSocks.Socket.ReleaseSharedSocket(nextHopEP, sock); sock = null; } } }