NetStandardSocket Class Reference
[Networking]

The basic network socket class. More...

#include <netsocket.h>

Inheritance diagram for NetStandardSocket:

Inheritance graph
[legend]
Collaboration diagram for NetStandardSocket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

DECLSPEC NetStandardSocket (const char *name, NetBasicManager *p, TCPsocket connection=0)
DECLSPEC NetStandardSocket (const char *name, NetBasicManager *p, IPaddress ip, int filter=0)
DECLSPEC NetStandardSocket (TiXmlElement *el, NetBasicManager *p)
virtual const char * getClassName ()
virtual bool sendData (char *data, unsigned int size)
virtual DECLSPEC bool sendData (char *data, unsigned int size, Uint32 condition, void *buffer=NULL)
virtual DECLSPEC int readData (char *data, int maxsize)
virtual DECLSPEC char * readData (int *size)
void setReceiveCallback (BasicObject::Callback cb, BasicObject *o)

Public Attributes

Uint32 filter

Protected Member Functions

virtual DECLSPEC void onInit ()
virtual DECLSPEC bool onReceive ()
virtual DECLSPEC void onConnect ()

Detailed Description

The basic network socket class.

This class implements basic socket functions network communication. It works closely together with NetSimpleManager.

message-structure of a NetStandardSocket-message:


Constructor & Destructor Documentation

NetStandardSocket::NetStandardSocket ( const char *  name,
NetBasicManager p,
TCPsocket  connection = 0 
)

Constructor. Usually used only internally in the netrinjo engine.

Parameters:
connection the SDL TCPsocket to use, or NULL, if no connection is used.

NetStandardSocket::NetStandardSocket ( const char *  name,
NetBasicManager p,
IPaddress  ip,
int  filter = 0 
)

Constructor. Connects to a host.

Parameters:
ip the host's IP address, that should be connected.
filter the filter to use, when a message is sent, using a condition if (filter & condition) != 0 or condition == 0 then message will be sent
Warning:
this construction can take some time, if the host is not reachable immediatelly.

NetStandardSocket::NetStandardSocket ( TiXmlElement el,
NetBasicManager p 
)

Constructor. Uses XML-data.

Parameters:
el the XML-data, the attribute "Filter" can be used to specify the value for filter
Test:
this function


Member Function Documentation

virtual const char* NetStandardSocket::getClassName (  )  [inline, virtual]

This function should be overriden in every sub-class of BasicObject!

Returns:
the name of the class.

Reimplemented from BasicObject.

Reimplemented in NetPeerSocket.

bool NetStandardSocket::sendData ( char *  data,
unsigned int  size 
) [virtual]

Sends data, preceded by a word (2 bytes) containing the size, to the host.

Parameters:
data the data to send
size the size of data
Returns:
true on success, false if disconnected.

Reimplemented from NetSocket.

bool NetStandardSocket::sendData ( char *  data,
unsigned int  size,
Uint32  condition,
void *  buffer = NULL 
) [virtual]

Sends data to the host, if a condition is true. It automatically disconnects, if an error occurs when sending the data.

Parameters:
data the whole content of the message to send
size the content's size in bytes
condition a condition number, if zero, the data will always be sent
buffer can be either reserved space for creating the message, or NULL if buffer is specified, sending data will be faster, especially, if size is big
Returns:
true, if either the message was sent successfully or the condition was not fulfilled; false if disconnected

int NetStandardSocket::readData ( char *  data,
int  maxsize 
) [virtual]

Receives data from the host. Using this is faster than NetSocket::readData(), but uses its own data-structure (2 Bytes specifying the size are prepended to each packet). So also the other host has to use this class's methods to send and receive data.

See also:
NetSocket::readData(void*, int)

Reimplemented from NetSocket.

char * NetStandardSocket::readData ( int *  size  )  [virtual]

Similar to readData(void*, int), but allocates memory to store the received data (this has to be freed after usage!).

Parameters:
size if not NULL, the number of bytes received or an error-code is stored here
Returns:
a pointer to the received data, that has to be freed after usage; or NULL on error

Implements NetSocket.

void NetStandardSocket::setReceiveCallback ( BasicObject::Callback  cb,
BasicObject o 
) [inline]

Sets the callback function.

Parameters:
cb the function pointer
o the recieving object

void NetStandardSocket::onInit (  )  [protected, virtual]

Initializes the object's variables by reading data from the XML element. If there were no XML data used for creation, nothing is done. This function calls onInit() of its children recursively (after it has inited itself). It is highly recommended to call BasicObject::onInit(), usually at the end of the onInit() method, when overwriting it in a derived class.

Reimplemented from NetSocket.

bool NetStandardSocket::onReceive (  )  [protected, virtual]

Calls the callback function, as set by setReceiveCallback(). The 3rd param of the callback-function is used as a pointer to a boolean value. If this is set false, the socket will close.

Returns:
true by default, false if the value of the pointer in the 3rd param is set to false.

Reimplemented from NetSocket.

Reimplemented in NetPeerSocket.

void NetStandardSocket::onConnect (  )  [protected, virtual]

Called, after a connection has been established successfully. If you want to overwrite this method, do not forget to call the parent class's onConnect();

Reimplemented from NetSocket.

Reimplemented in NetPeerSocket.


Member Data Documentation

Uint32 NetStandardSocket::filter

Used, when sending conditioned messages if (filter & condition) != 0 or condition == 0 then message will be sent


The documentation for this class was generated from the following files:
Generated on Wed May 9 17:36:31 2007 for netrinjo by  doxygen 1.5.1