#import <Foundation/Foundation.h> #import <Network/Network.h> typedef void (^RecvPacketHandler)(NSData * _Nonnull packetData, NSString * _Nonnull remoteEndpoint); typedef void (^SendCompletionHandler)(NSError * _Nonnull error); @interface UDPListener : NSObject { @private RecvPacketHandler _recvPacketHandler; NSMutableDictionary<NSString *, nw_connection_t> * _childConnections; } @property (nonatomic, retain, nullable) nw_listener_t listener; @property (nonatomic, retain, nullable) dispatch_queue_t queue; - (nullable instancetype)init; - (nullable instancetype)initWithQueue:(dispatch_queue_t __nullable)queue; - (void)startListening:(uint16_t)port packetHandler:(nonnull RecvPacketHandler)packetHandler; - (void)stopListening; - (void)sendPacket:(nonnull NSData *)packetData toEndpoint:(nonnull NSString *)remoteEndpoint completionHandler:(nullable SendCompletionHandler)completionHandler; @end // UDPListener