Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00324.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00324.php on line 2
The ARGoS Website

argos::CTCPSocket Class Reference

#include <tcp_socket.h>

Public Member Functions

 CTCPSocket (int n_stream=-1)
 
 ~CTCPSocket ()
 
bool IsConnected () const
 Returns true if the socket is connected. More...
 
int GetStream () const
 Returns the socket stream. More...
 
const std::string & GetAddress () const
 Returns a string containing the IPv4 address in dot notation. More...
 
void Connect (const std::string &str_hostname, SInt32 n_port)
 Connects this socket to the specified hostname and port. More...
 
void Listen (SInt32 n_port, SInt32 n_queue_length=10)
 Listens for connections on the specified local port. More...
 
void Accept (CTCPSocket &c_socket)
 Accept a connection from a client. More...
 
void Disconnect ()
 Close the socket. More...
 
void SendBuffer (const UInt8 *pun_buffer, size_t un_size)
 Sends the passed buffer through the socket. More...
 
bool ReceiveBuffer (UInt8 *pun_buffer, size_t un_size)
 Fills the passed buffer with the data received through the socket. More...
 
void SendByteArray (const CByteArray &c_byte_array)
 Sends the passed byte array through the socket. More...
 
bool ReceiveByteArray (CByteArray &c_byte_array)
 Receives the passed byte array through the socket. More...
 

Detailed Description

Definition at line 13 of file tcp_socket.h.

Constructor & Destructor Documentation

argos::CTCPSocket::CTCPSocket ( int  n_stream = -1)

Definition at line 18 of file tcp_socket.cpp.

argos::CTCPSocket::~CTCPSocket ( )

Definition at line 25 of file tcp_socket.cpp.

Member Function Documentation

void argos::CTCPSocket::Accept ( CTCPSocket c_socket)

Accept a connection from a client.

Internally, the connection is forced to be only IPv4. Before calling this function, you must first call Listen() to setup connection listening.

Parameters
c_socketThe socket on which the connection has been created
Exceptions
CARGoSExceptionin case of error
See also
Listen
Connect

Definition at line 127 of file tcp_socket.cpp.

void argos::CTCPSocket::Connect ( const std::string &  str_hostname,
SInt32  n_port 
)

Connects this socket to the specified hostname and port.

Internally, the connection is forced to be only IPv4.

Parameters
str_hostnameThe wanted hostname
n_portThe wanted port
Exceptions
CARGoSExceptionin case of error
See also
Accept

Definition at line 32 of file tcp_socket.cpp.

void argos::CTCPSocket::Disconnect ( )

Close the socket.

Exceptions
CARGoSExceptionin case of error

Definition at line 143 of file tcp_socket.cpp.

const std::string& argos::CTCPSocket::GetAddress ( ) const
inline

Returns a string containing the IPv4 address in dot notation.

Returns
A string containing the IPv4 address in dot notation.

Definition at line 41 of file tcp_socket.h.

int argos::CTCPSocket::GetStream ( ) const
inline

Returns the socket stream.

Returns
the socket stream.

Definition at line 33 of file tcp_socket.h.

bool argos::CTCPSocket::IsConnected ( ) const
inline

Returns true if the socket is connected.

Returns
true if the socket is connected.

Definition at line 25 of file tcp_socket.h.

void argos::CTCPSocket::Listen ( SInt32  n_port,
SInt32  n_queue_length = 10 
)

Listens for connections on the specified local port.

Internally, the connection is forced to be only IPv4. To actually accept connections, you must call Accept() after calling this function.

Parameters
n_portThe wanted port
n_queue_lengthThe maximum length of the queue of pending connections (also called the backlog)
Exceptions
CARGoSExceptionin case of error
See also
Accept

Definition at line 72 of file tcp_socket.cpp.

bool argos::CTCPSocket::ReceiveBuffer ( UInt8 pun_buffer,
size_t  un_size 
)

Fills the passed buffer with the data received through the socket.

Parameters
pun_bufferThe buffer to fill
un_sizeThe size of the buffer
Returns
true if the buffer was filled correctly; false if the connection was closed by the other peer
Exceptions
CARGoSExceptionin case of error

Definition at line 169 of file tcp_socket.cpp.

bool argos::CTCPSocket::ReceiveByteArray ( CByteArray c_byte_array)

Receives the passed byte array through the socket.

Internally, this function first receives the size of the byte array as a long int, and then receives the content of the byte array. It is meant to the be used in conjunction with SendByteArray().

Parameters
c_byte_arrayThe byte array
Returns
true if the buffer was filled correctly; false if the connection was closed by the other peer
Exceptions
CARGoSExceptionin case of error
See also
CByteArray
ReceiveBuffer
SendByteArray

Definition at line 199 of file tcp_socket.cpp.

void argos::CTCPSocket::SendBuffer ( const UInt8 pun_buffer,
size_t  un_size 
)

Sends the passed buffer through the socket.

Parameters
pun_bufferThe wanted buffer
un_sizeThe size of the buffer
Exceptions
CARGoSExceptionin case of error

Definition at line 152 of file tcp_socket.cpp.

void argos::CTCPSocket::SendByteArray ( const CByteArray c_byte_array)

Sends the passed byte array through the socket.

Internally, this function first sends the size of the byte array as a long int, and then sends the content of the byte array. It is meant to the be used in conjunction with ReceiveByteArray().

Parameters
c_byte_arrayThe byte array
Exceptions
CARGoSExceptionin case of error
See also
CByteArray
SendBuffer
ReceiveByteArray

Definition at line 188 of file tcp_socket.cpp.