Neal Horman / Socket

Fork of Socket by mbed official

Embed: (wiki syntax)

« Back to documentation index

UDPSocket Class Reference

UDPSocket Class Reference

This is a C++ abstraction for UDP networking sockets. More...

#include <UDPSocket.h>

Inherits Socket.

Public Member Functions

 UDPSocket ()
 Instantiate a UDP Socket.
int bind (int port)
 Bind a UDP Server Socket to a specific port For a listening socket, bind the socket to the following port.
int sendTo (UDPPacket &packet, int timeout_ms=0)
 Send a packet to the remote host.
int receiveFrom (UDPPacket &packet, int timeout_ms=0)
 Receive data from a remote host.

Detailed Description

This is a C++ abstraction for UDP networking sockets.

Definition at line 29 of file UDPSocket.h.


Constructor & Destructor Documentation

UDPSocket (  )

Instantiate a UDP Socket.

Definition at line 25 of file UDPSocket.cpp.


Member Function Documentation

int bind ( int  port )

Bind a UDP Server Socket to a specific port For a listening socket, bind the socket to the following port.

Parameters:
portThe port to listen for incoming connections on, using 0 here will select a random port.
Returns:
0 on success, -1 on failure.

Definition at line 33 of file UDPSocket.cpp.

int receiveFrom ( UDPPacket &  packet,
int  timeout_ms = 0 
)

Receive data from a remote host.

If a message is too long to fit in the supplied packet, excess bytes are discarded.

Parameters:
packetUDP Packet received from the remote host
timeoutThe maximum amount of time in ms to wait while trying to receive data.
Returns:
the number of received bytes on success (>=0) or -1 on failure

Definition at line 67 of file UDPSocket.cpp.

int sendTo ( UDPPacket &  packet,
int  timeout_ms = 0 
)

Send a packet to the remote host.

Parameters:
packetUDP Packet to be sent to the remote host
timeoutThe maximum amount of time in ms to wait while trying to send the buffer.
Returns:
the number of written bytes on success (>=0) or -1 on failure

Definition at line 53 of file UDPSocket.cpp.