UDPEndpoint
@interface UDPEndpoint : NSObject
A class to represent a communications endpoint based on UDP sockets. IPv4/IPv6 are both supported. A UDPEndpoint enables a UDP server to be started by binding the underlying socket to a specified port and provides a method to be scheduled for checking for incoming packets. In client mode, a socket is created to target a remote address and port. Data packets can then be sent to the remote UDP endpoint by calling -sendData:.
-
Unused default initialiser
Declaration
Objective-C
- (instancetype)init;
Return Value
initialised UDPEndpoint instance
-
Initialise a UDPEndpoint instance with a buffer size
Declaration
Objective-C
- (id)initWithBufferSize:(size_t)size;
Swift
init!(bufferSize size: Int)
Parameters
size
buffer size e.g. size of protocol message
Return Value
initialised UDPEndpoint instance
-
- Starts a server on the specified port. Will call the -echo:didStartWithAddress: delegate method on success and the -echo:didStopWithError: on failure. After that, the various ‘data’ delegate methods may be called. *
- - parameter: port an available local port
Declaration
Objective-C
- (void)startServerOnPort:(NSUInteger)port;
Swift
func startServer(onPort port: UInt)
Parameters
port
an available local port
-
- Starts a client targetting the specified host and port. Will call -echo:didStartWithAddress: delegate method on success and the -echo:didStopWithError: on failure. At that point you can call -sendData: to send data to the server and the various ‘data’ delegate methods may be called.
* * - parameter: hostName remote host address () * - parameter: port remote port to be targetted
Declaration
Objective-C
- (void)startConnectedToHostName:(NSString *)hostName port:(NSUInteger)port;
Swift
func startConnected(toHostName hostName: String!, port: UInt)
Parameters
hostName
remote host address ()
port
remote port to be targetted
-
- On the client, sends the specified data to the server. The -echo:didSendData:toAddress: or -echo:didFailToSendData:toAddress:error: delegate method will be called to indicate the success or failure of the send, and the -echo:didReceiveData:fromAddress: delegate method will be called if a response is received.
* * - parameter: data bytes to be sent
Declaration
Objective-C
- (void)sendData:(NSData *)data;
Swift
func send(_ data: Data!)
Parameters
data
bytes to be sent
-
- Will stop the object, preventing any future network operations or delegate method calls until the next start call.
Declaration
Objective-C
- (void)stop;
Swift
func stop()
-
Get buffer used for sending
Declaration
Objective-C
- (uint8_t *)getSendBuffer;
Swift
func getSendBuffer() -> UnsafeMutablePointer
Return Value
pointer to send buffer
-
Get buffer used for receiving
Declaration
Objective-C
- (uint8_t *)getReceiveBuffer;
Swift
func getReceiveBuffer() -> UnsafeMutablePointer
Return Value
pointer to receive buffer
-
Method to check if packets are available . This method can be called periodically on a separate thread.
Declaration
Objective-C
- (BOOL)checkForIncomingPackets:(uint32_t)timeout_us;
Swift
func check(forIncomingPackets timeout_us: UInt32) -> Bool
Parameters
timeout_us
timeout for select call to block when waiting for on socket descriptor to become ready for reading
Return Value
true if select call did not return an error
-
Start a listener thread to check for incoming packets.
Declaration
Objective-C
- (void)startListenerThreadIfNeeded;
Swift
func startListenerThreadIfNeeded()
-
A delegate that is notified about new packet arrival, packet send success, etc
Declaration
Objective-C
@property (readwrite, nonatomic) id<UDPCommsDelegate> delegate;
Swift
weak var delegate: UDPCommsDelegate! { get set }
-
Is UDPEndpoint running in server mode?
Declaration
Objective-C
@property (readonly, getter=isServer, assign, nonatomic) BOOL server;
Swift
var isServer: Bool { get }
-
Name of remote host targetted for sending data. Property value only valid in client mode.
Declaration
Objective-C
@property (readonly, copy, nonatomic) NSString *hostName;
Swift
var hostName: String! { get }
-
Address of remote host targetted for sending data. Property value only valid in client mode after successful start.
Declaration
Objective-C
@property (readonly, copy, nonatomic) NSData *hostAddress;
Swift
var hostAddress: Data! { get }
-
Remote host’s port number targetted for sending data. Property value only valid in client mode
Declaration
Objective-C
@property (readonly, assign, nonatomic) NSUInteger port;
Swift
var port: UInt { get }