#include <netsocket.h>
Inheritance diagram for NetStandardSocket:
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 () |
This class implements basic socket functions network communication. It works closely together with NetSimpleManager.
message-structure of a NetStandardSocket-message:
NetStandardSocket::NetStandardSocket | ( | const char * | name, | |
NetBasicManager * | p, | |||
TCPsocket | connection = 0 | |||
) |
Constructor. Usually used only internally in the netrinjo engine.
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.
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 |
NetStandardSocket::NetStandardSocket | ( | TiXmlElement * | el, | |
NetBasicManager * | p | |||
) |
Constructor. Uses XML-data.
el | the XML-data, the attribute "Filter" can be used to specify the value for filter |
virtual const char* NetStandardSocket::getClassName | ( | ) | [inline, virtual] |
This function should be overriden in every sub-class of BasicObject!
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.
data | the data to send | |
size | the size of data |
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.
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 |
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.
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!).
size | if not NULL, the number of bytes received or an error-code is stored here |
Implements NetSocket.
void NetStandardSocket::setReceiveCallback | ( | BasicObject::Callback | cb, | |
BasicObject * | o | |||
) | [inline] |
Sets the callback function.
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.
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.
Uint32 NetStandardSocket::filter |
Used, when sending conditioned messages if (filter & condition) != 0 or condition == 0 then message will be sent