TcpCx Class Reference
[Network]

Implements TCP networking.

This class implements TCP/IP data connections. Nagle algorithm is turned off, to speed up little but frequent transfers. More...

#include <TcpCx.hh>

Inheritance diagram for TcpCx:

Inheritance graph
[legend]
List of all members.

Public Member Functions

void connect (const char *host, int port)
 Open a TCP connection to an host, to a specified port.
void listen (int port)
 Prepare to accepts connection.
TcpCxaccept ()
 Accept any connection from the outside.

Protected Member Functions

virtual bool pollInternal (int *timeout)
virtual int recvData (bool use_exception)
virtual void sendData (unsigned char *data, unsigned size)
virtual void print (std::ostream &os) const
 Print some debug info.

Detailed Description

Implements TCP networking.

This class implements TCP/IP data connections. Nagle algorithm is turned off, to speed up little but frequent transfers.

 TcpCx* cx = new TcpCx;
 Packet* p;

 cx->connect("localhost", 4242);
 if (!cx->poll(5)) {
   delete cx;// connection failed
   return;
 }
 cx->send(Packet(CX_INIT, 1));
 if (!cx->poll(5)) {
   delete cx; // can't receive anything
   return;
 }
 p = cx->receive();
 delete cx; // close connection


Member Function Documentation

TcpCx * TcpCx::accept (  ) 

Accept any connection from the outside.

For server.

Returns:
A newly instance of TcpCx, connected with a remote host.
Note:
This function blocks. If you don't want that, use poll() before.
Exceptions:
NetError Thrown on OS error.

void TcpCx::connect ( const char *  host,
int  port 
)

Open a TCP connection to an host, to a specified port.

For client.

Parameters:
host Host to connect to. Could be an IP adresse or an host name resolvable by the operating system.
Note:
This function doesn't block. Actually, the connection could not be made when this function returns. Call poll to check when connected.
Parameters:
port Port to connect to (1-65535).
Exceptions:
NetError Thrown on OS error.

void TcpCx::listen ( int  port  ) 

Prepare to accepts connection.

For server.

Parameters:
port Will accept connection on this port.
Note:
Currently, binds on IN_ADDR_ANY. This function doesn't block.
Exceptions:
NetError Thrown on OS error.


The documentation for this class was generated from the following files:
Generated on Sat Jun 23 16:13:59 2007 for Stechec/TBT by  doxygen 1.4.7