hoa_socket::Socket Class Reference

TCP socket. More...

#include <socket.h>

Collaboration diagram for hoa_socket::Socket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void Connect (const std::string &host, uint16 port)
 Connects to a server.
void Disconnect ()
 Disconnects from the server.
bool IsConnected ()
 Checks whether the socket is connected.
bool IsQueued (uint32 wait_time=0)
 Checks if there is any incoming data in the queue.
std::string ReadLine ()
 Reads one line.
uint32 RecvBinary (void *location, uint32 maxlen)
 Reads binary data.
void ScanLine (const char *format,...)
 Scans one line, in scanf style.
uint32 SendBinary (void *data, uint32 len)
 Sends binary data.
 Socket ()
 Standard constructor.
void Write (const char *format,...)
 Writes textual data.
 ~Socket ()
 Standard destructor.

Private Attributes

bool connected
SDLNet_SocketSet set
TCPsocket sock

Detailed Description

TCP socket.

****************************************************************************

TCP client socket with basic connectivity functionality.

Note:
1) Server functionality will be added on soon

Definition at line 41 of file socket.h.


Constructor & Destructor Documentation

hoa_socket::Socket::Socket (  ) 

Standard constructor.

Initialises SDL_net if it is not already started, and creates a TCP socket

Definition at line 22 of file socket.cpp.

References connected, num_sockets, set, and sock.

hoa_socket::Socket::~Socket (  ) 

Standard destructor.

Quits SDL_net if it is not needed, disconnects if the TCP socket is still connected

Definition at line 32 of file socket.cpp.

References Disconnect(), IsConnected(), and num_sockets.

Here is the call graph for this function:


Member Function Documentation

void hoa_socket::Socket::Connect ( const std::string &  host,
uint16  port 
)

Connects to a server.

Parameters:
host The hostname to which to connect
port The TCP port number with which to connect

Definition at line 46 of file socket.cpp.

References connected, set, and sock.

Referenced by hoa_utils::IsLatestVersion().

void hoa_socket::Socket::Disconnect (  ) 

Disconnects from the server.

Definition at line 64 of file socket.cpp.

References connected, IsConnected(), set, and sock.

Referenced by hoa_utils::IsLatestVersion(), and ~Socket().

Here is the call graph for this function:

bool hoa_socket::Socket::IsConnected (  ) 

Checks whether the socket is connected.

Definition at line 41 of file socket.cpp.

References connected.

Referenced by Disconnect(), hoa_utils::IsLatestVersion(), IsQueued(), RecvBinary(), SendBinary(), and ~Socket().

bool hoa_socket::Socket::IsQueued ( uint32  wait_time = 0  ) 

Checks if there is any incoming data in the queue.

Parameters:
wait_time Time to wait for incoming data, in milliseconds

Definition at line 73 of file socket.cpp.

References IsConnected(), and set.

Referenced by hoa_utils::IsLatestVersion().

Here is the call graph for this function:

std::string hoa_socket::Socket::ReadLine (  ) 

Reads one line.

Returns:
One line of text. Note that this is a std::string

Definition at line 105 of file socket.cpp.

References RecvBinary().

Referenced by ScanLine().

Here is the call graph for this function:

uint32 hoa_socket::Socket::RecvBinary ( void *  location,
uint32  maxlen 
)

Reads binary data.

Parameters:
d A pointer to the location in which to store the data
len The length of the data up to which to read
Returns:
The amount of data actually read

Definition at line 85 of file socket.cpp.

References IsConnected(), and sock.

Referenced by ReadLine().

Here is the call graph for this function:

void hoa_socket::Socket::ScanLine ( const char *  format,
  ... 
)

Scans one line, in scanf style.

Parameters:
fmt The format to scan
... Other arguments, following from the scanf format given

Definition at line 123 of file socket.cpp.

References ReadLine().

Referenced by hoa_utils::IsLatestVersion().

Here is the call graph for this function:

uint32 hoa_socket::Socket::SendBinary ( void *  data,
uint32  len 
)

Sends binary data.

Parameters:
d A pointer to a block of data
len The number of bytes of data
Returns:
The amount of data sent

Definition at line 79 of file socket.cpp.

References IsConnected(), and sock.

Here is the call graph for this function:

void hoa_socket::Socket::Write ( const char *  format,
  ... 
)

Writes textual data.

Parameters:
fmt The format of the data, in printf style
... Other arguments, following from the format given (the format is a const char*, don't forget)

Definition at line 91 of file socket.cpp.

Referenced by hoa_utils::IsLatestVersion().


Member Data Documentation

bool hoa_socket::Socket::connected [private]

Definition at line 46 of file socket.h.

Referenced by Connect(), Disconnect(), IsConnected(), and Socket().

SDLNet_SocketSet hoa_socket::Socket::set [private]

Definition at line 45 of file socket.h.

Referenced by Connect(), Disconnect(), IsQueued(), and Socket().

TCPsocket hoa_socket::Socket::sock [private]

Definition at line 44 of file socket.h.

Referenced by Connect(), Disconnect(), RecvBinary(), SendBinary(), and Socket().


The documentation for this class was generated from the following files:
Generated on Fri Jul 6 23:16:05 2007 for Hero of Allacrost by  doxygen 1.5.1