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::TCPSocket Class Reference

TCP/IP connection socket class. More...

#include <tcp_socket.h>

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

Public Member Functions

 TCPSocket (const char *hostname, const int port)
 constructor for client socket More...
 
 ~TCPSocket ()
 destructor. close socket automatically
 
int connect ()
 make connection More...
 
int writeToStream (const char *data, const std::size_t len)
 send stream data to the connected host. More...
 
int readFromStream (char *buf, const std::size_t len)
 receive stream data 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

TCP/IP connection socket class.

Constructor & Destructor Documentation

◆ TCPSocket()

rcsc::TCPSocket::TCPSocket ( 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

◆ connect()

int rcsc::TCPSocket::connect ( )

make connection

Returns
-1 on error, otherwise 0

◆ readFromStream()

int rcsc::TCPSocket::readFromStream ( char *  buf,
const std::size_t  len 
)

receive stream data from the connected remote host.

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

◆ writeToStream()

int rcsc::TCPSocket::writeToStream ( const char *  data,
const std::size_t  len 
)

send stream data 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.

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