public static void Bind(int port, Action <OscPacketEventArgs> packetReceivedDelegate) { UdpListener listener = null; lock (_listeners) { if (!_listeners.TryGetValue(port, out listener)) { listener = new UdpListener(port); _listeners[port] = listener; } } listener?.AddDelegate(packetReceivedDelegate); }
public static bool UnBind(int port, Action <OscPacketEventArgs> packetReceivedDelegate) { UdpListener listener = null; if (_listeners.TryRemove(port, out listener) && listener != null) { listener.RemoveDelegate(packetReceivedDelegate); if (listener.DelegatesCount() == 0) { listener.Dispose(); } return(true); } return(false); }