sf::SocketTCP Class Reference

SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower). More...

#include <SocketTCP.hpp>

List of all members.

Public Member Functions

 SocketTCP ()
 Default constructor.
void SetBlocking (bool blocking)
 Change the blocking state of the socket.
Socket::Status Connect (unsigned short port, const IPAddress &host, float timeout=0.f)
 Connect to another computer on a specified port.
bool Listen (unsigned short port)
 Listen to a specified port for incoming data or connections.
Socket::Status Accept (SocketTCP &connected, IPAddress *address=NULL)
 Wait for a connection (must be listening to a port).
Socket::Status Send (const char *data, std::size_t sizeInBytes)
 Send an array of bytes to the host (must be connected first).
Socket::Status Receive (char *data, std::size_t maxSize, std::size_t &sizeReceived)
 Receive an array of bytes from the host (must be connected first).
Socket::Status Send (Packet &packet)
 Send a packet of data to the host (must be connected first).
Socket::Status Receive (Packet &packet)
 Receive a packet from the host (must be connected first).
bool Close ()
 Close the socket.
bool IsValid () const
 Check if the socket is in a valid state ; this function can be called any time to check if the socket is OK.
bool operator== (const SocketTCP &other) const
 Comparison operator ==.
bool operator!= (const SocketTCP &other) const
 Comparison operator !=.
bool operator< (const SocketTCP &other) const
 Comparison operator <.

Friends

class Selector< SocketTCP >

Detailed Description

SocketTCP wraps a socket using TCP protocol to send data safely (but a bit slower).

Definition at line 45 of file SocketTCP.hpp.


Constructor & Destructor Documentation

sf::SocketTCP::SocketTCP (  ) 

Default constructor.

Definition at line 47 of file SocketTCP.cpp.


Member Function Documentation

Socket::Status sf::SocketTCP::Accept ( SocketTCP connected,
IPAddress address = NULL 
)

Wait for a connection (must be listening to a port).

This function will block if the socket is blocking

Parameters:
connected : Socket containing the connection with the connected client
address : Pointer to an address to fill with client infos
Returns:
Status code

This function will block if the socket is blocking

Definition at line 206 of file SocketTCP.cpp.

bool sf::SocketTCP::Close (  ) 

Close the socket.

Returns:
True if operation has been successful

Definition at line 406 of file SocketTCP.cpp.

Socket::Status sf::SocketTCP::Connect ( unsigned short  port,
const IPAddress host,
float  timeout = 0.f 
)

Connect to another computer on a specified port.

Parameters:
port : Port to use for transfers (warning : ports < 1024 are reserved)
host : IP Address of the host to connect to
timeout : Maximum time to wait, in seconds (0 by default : no timeout) (this parameter is ignored for non-blocking sockets)
Returns:
True if operation has been successful

Definition at line 70 of file SocketTCP.cpp.

bool sf::SocketTCP::IsValid (  )  const

Check if the socket is in a valid state ; this function can be called any time to check if the socket is OK.

Returns:
True if the socket is valid

Definition at line 429 of file SocketTCP.cpp.

bool sf::SocketTCP::Listen ( unsigned short  port  ) 

Listen to a specified port for incoming data or connections.

Parameters:
port : Port to listen to
Returns:
True if operation has been successful

Definition at line 169 of file SocketTCP.cpp.

bool sf::SocketTCP::operator!= ( const SocketTCP other  )  const

Comparison operator !=.

Parameters:
other : Socket to compare
Returns:
True if *this != other

Definition at line 447 of file SocketTCP.cpp.

bool sf::SocketTCP::operator< ( const SocketTCP other  )  const

Comparison operator <.

Provided for compatibility with standard containers, as comparing two sockets doesn't make much sense...

Parameters:
other : Socket to compare
Returns:
True if *this < other

Provided for compatibility with standard containers, as comparing two sockets doesn't make much sense...

Definition at line 458 of file SocketTCP.cpp.

bool sf::SocketTCP::operator== ( const SocketTCP other  )  const

Comparison operator ==.

Parameters:
other : Socket to compare
Returns:
True if *this == other

Definition at line 438 of file SocketTCP.cpp.

Socket::Status sf::SocketTCP::Receive ( Packet packet  ) 

Receive a packet from the host (must be connected first).

This function will block if the socket is blocking

Parameters:
packet : Packet to fill with received data
Returns:
Status code

This function will block if the socket is blocking

Definition at line 340 of file SocketTCP.cpp.

Socket::Status sf::SocketTCP::Receive ( char *  data,
std::size_t  maxSize,
std::size_t &  sizeReceived 
)

Receive an array of bytes from the host (must be connected first).

This function will block if the socket is blocking

Parameters:
data : Pointer to a byte array to fill (make sure it is big enough)
maxSize : Maximum number of bytes to read
sizeReceived : Number of bytes received
Returns:
Status code

This function will block if the socket is blocking

Definition at line 272 of file SocketTCP.cpp.

Socket::Status sf::SocketTCP::Send ( Packet packet  ) 

Send a packet of data to the host (must be connected first).

Parameters:
packet : Packet to send
Returns:
Status code

Definition at line 314 of file SocketTCP.cpp.

Socket::Status sf::SocketTCP::Send ( const char *  data,
std::size_t  sizeInBytes 
)

Send an array of bytes to the host (must be connected first).

Parameters:
data : Pointer to the bytes to send
sizeInBytes : Number of bytes to send
Returns:
Status code

Definition at line 235 of file SocketTCP.cpp.

void sf::SocketTCP::SetBlocking ( bool  blocking  ) 

Change the blocking state of the socket.

The default behaviour of a socket is blocking

Parameters:
blocking : Pass true to set the socket as blocking, or false for non-blocking

Definition at line 56 of file SocketTCP.cpp.


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