LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | List of all members
rcsc::UDPSocket Class Reference

UDP/IP connection socket class. More...

#include <udp_socket.h>

Inheritance diagram for rcsc::UDPSocket:
Inheritance graph
[legend]
Collaboration diagram for rcsc::UDPSocket:
Collaboration graph
[legend]

Public Member Functions

 UDPSocket (const int port)
 constructor for server socket More...
 
 UDPSocket (const char *hostname, const int port)
 constructor for client socket More...
 
 ~UDPSocket ()
 destructor. close socket automatically
 
int writeDatagram (const char *data, const size_t len)
 send datagram packet to the connected host. More...
 
int writeDatagram (const char *data, const size_t len, const HostAddress &dest)
 send datagram packet to the specified host. More...
 
int readDatagram (char *buf, const size_t len)
 receive datagram packet from the connected remote host. More...
 
int readDatagram (char *buf, const size_t len, HostAddress *from)
 receive datagram packet from the connected remote host. More...
 
- Public Member Functions inherited from rcsc::AbstractSocket
virtual ~AbstractSocket ()
 destructor. close socket automatically
 
int fd () const
 returns socket file descriptor More...
 
bool isOpen () const
 check if socket is opened or not. More...
 
int close ()
 close socket More...
 
const HostAddresslocalAddress () const
 get the local address object More...
 
HostAddress::PortNumber localPort () const
 get the port number of destination address More...
 
const HostAddresspeerAddress () const
 get the peer address object More...
 
std::string peerName () const
 get the host name of destination address More...
 
HostAddress::PortNumber peerPort () const
 get the port number of destination address More...
 

Additional Inherited Members

- Public Types inherited from rcsc::AbstractSocket
enum  SocketType { DATAGRAM_TYPE , STREAM_TYPE , UNKNOWN_TYPE }
 socket type definition
 
- Protected Member Functions inherited from rcsc::AbstractSocket
 AbstractSocket ()
 protected constructor to prevent instantiation
 
bool open (const SocketType type)
 open socket More...
 
bool bind (const HostAddress::PortNumber port)
 bind the socket to local address More...
 
bool setPeerAddress (const char *hostname, const HostAddress::PortNumber port)
 set the address info of the specified remote host. More...
 
int setNonBlocking ()
 set non blocking mode. More...
 
int connectToPresetAddr ()
 connect to address set by setAddr() More...
 
- Protected Attributes inherited from rcsc::AbstractSocket
HostAddress M_local_address
 local address
 
HostAddress M_peer_address
 destination address
 

Detailed Description

UDP/IP connection socket class.

Constructor & Destructor Documentation

◆ UDPSocket() [1/2]

rcsc::UDPSocket::UDPSocket ( const int  port)
explicit

constructor for server socket

Parameters
portport number to receive packet.

◆ UDPSocket() [2/2]

rcsc::UDPSocket::UDPSocket ( const char *  hostname,
const int  port 
)

constructor for client socket

Parameters
hostnameremote host name (or IP address)
portport number to send packet

Member Function Documentation

◆ readDatagram() [1/2]

int rcsc::UDPSocket::readDatagram ( char *  buf,
const size_t  len 
)

receive datagram packet from the connected remote host.

Parameters
bufbuffer to receive data
lenmaximum length of the buffer array
Return values
0error occured and errno is EWOULDBLOCK
-1error occured
Returns
the length of received data.

◆ readDatagram() [2/2]

int rcsc::UDPSocket::readDatagram ( char *  buf,
const size_t  len,
HostAddress from 
)

receive datagram packet from the connected remote host.

Parameters
bufbuffer to receive data
lenmaximum length of the buffer array
addrthe source host address is set to this variable
Return values
0error occured and errno is EWOULDBLOCK
-1error occured
Returns
the length of received data.

◆ writeDatagram() [1/2]

int rcsc::UDPSocket::writeDatagram ( const char *  data,
const size_t  len 
)

send datagram packet to the connected host.

Parameters
datathe pointer to the data to be sent.
lenthe length of data.
Returns
the length of sent data if successfuly sent, otherwise -1.

◆ writeDatagram() [2/2]

int rcsc::UDPSocket::writeDatagram ( const char *  data,
const size_t  len,
const HostAddress dest 
)

send datagram packet to the specified host.

Parameters
datathe pointer to the data to be sent.
lenthe length of data.
destthe target host address
Returns
the length of sent data if successfuly sent, otherwise -1.

The documentation for this class was generated from the following file: