CRM32Pro_INetwork Class Reference
[MODULE 13: INetwork v4.10, network interface]

INetwork. More...


Detailed Description

INetwork.

Network interface.

List of all members.

Public Member Functions

unsigned char ConnectTo (char *host, unsigned short port, char *user, unsigned int passwd)
 Connect to a server.
unsigned char CreateServer (unsigned short port, unsigned int passwd, unsigned char dedicated)
 Create a server.
void FreeData (char *&buf)
 Free data received from ReceiveData() once you have processed it. You must always use it to avoid memory leaks.
unsigned char GetClientsInfo (sClientInfo **cinfo)
 Get current information stored locally about all connected clients.
unsigned int GetMyIP ()
 Get my IP if any.
char * GetMyUserName ()
 Get my user name when I am a client and I am already connected to a server.
void Info ()
 Print a lot of useful information.
unsigned char Init (char m_log)
 Initialize the network system.
unsigned char IsClient ()
 Check if we are running as client.
unsigned char IsServer ()
 Check if we are running as server or if the server is active.
unsigned char QueryClientsInfo ()
 Query to get all current clients with updated information.
unsigned char QueryKillClient ()
 Query to kill this client.
unsigned char QueryKillServer ()
 Query to close the server (and all the connected clients).
void Quit ()
 Close the network system.
unsigned char ReceiveData (char **buf, unsigned int *size)
 Receive data from the server.
unsigned char SendData (char *buff, int size, char isquery=1)
 Send data to server using a blocking method.
void SetCoreServerCallback (int(*myCoreServer)(void *data, int size))
 Set a callback function to hook into server thread to evaluate the sent data.
void SetTimeOut (int ms)
 Set the connection timeout.

Member Function Documentation

unsigned char CRM32Pro_INetwork::ConnectTo ( char *  host,
unsigned short  port,
char *  user,
unsigned int  passwd 
)

Connect to a server.

It will try to connect during the current timeout (set by SetTimeOut()) before to return with error. With ESCAPE key it halts the attempt.

Parameters:
host host name or IP of your server
port port number where is listening your server
user name of your client. Must be unique. Maximum of 16 characters.
passwd password to connect to your server
Returns:
0 Failed
1 Ok
Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
unsigned char CRM32Pro_INetwork::CreateServer ( unsigned short  port,
unsigned int  passwd,
unsigned char  dedicated 
)

Create a server.

You only can create one server on your software.

Parameters:
port the port to listen all the incoming connections (clients)
passwd integer with the password to connect to this server
dedicated 1 to stop the execution flow of your program and running only as server.
0 to execute it in a separated thread and go on with your program execution flow.
Returns:
0 Failed
1 Ok
Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
void CRM32Pro_INetwork::FreeData ( char *&  buf  ) 

Free data received from ReceiveData() once you have processed it. You must always use it to avoid memory leaks.

Do not free by yourself this buffer, you must to use this member to free it.

Parameters:
buf pointer to received data
Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
unsigned char CRM32Pro_INetwork::GetClientsInfo ( sClientInfo **  cinfo  ) 

Get current information stored locally about all connected clients.

When a new client is connected or disconnected, its informormation will be updated automatically.
So the information table returned by this function will be always a valid one except the latency.
If you want to know the real latency, you have to call to QueryClientsInfo() before to call this method.

Parameters:
cinfo a pointer to the information. See sClientInfo struct to further information.
Returns:
number of clients. Used to browse through the received pointer to cinfo
Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
void CRM32Pro_INetwork::Info (  ) 

Print a lot of useful information.

Show Client and/or Server internal information: DataNets and bytes sent,received,refused. Incoming queue status...

Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
unsigned char CRM32Pro_INetwork::Init ( char  mode_log  ) 

Initialize the network system.

Parameters:
mode_log Internal logging mode: LOG_NULL,LOG_CONSOLE,LOG_FILE,LOG_FILEAPPEND
Returns:
0 Failed
1 Ok
Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
unsigned char CRM32Pro_INetwork::QueryClientsInfo (  ) 

Query to get all current clients with updated information.

Returns:
0 Failed. Next ReceiveData() will return an INETWORK_ERROR
1 Ok
Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
unsigned char CRM32Pro_INetwork::QueryKillClient (  ) 

Query to kill this client.

Returns:
0 Failed. Next ReceiveData() will return an INETWORK_ERROR
1 Ok
Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
unsigned char CRM32Pro_INetwork::QueryKillServer (  ) 

Query to close the server (and all the connected clients).

Returns:
0 Failed. Next ReceiveData() will return an INETWORK_ERROR
1 Ok
Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
unsigned char CRM32Pro_INetwork::ReceiveData ( char **  buff,
unsigned int *  size 
)

Receive data from the server.

This data may be generated by the server itself or by others clients which send its data to the server.
Incoming data is stored on an internal queue so you can fetch all data elements calling this function until you get a return value of 0.
Important note: data elements are automatically allocated and deallocated but once you have receive any of it using this function, INetwork do not manage anymore its automatic deletion.
So you MUST CALL FreeData() member when you finish to work with it to free it and to avoid a memory leaks.
An optional safe check, on your application side, to avoid data overflows, is to test if received data size is the same as your anticipated data size.

Parameters:
buff pointer to received data
size pointer to integer with the size of received data (if any)
Returns:
0 if there isn't anydata received. buff and size are set to NULL and -1 respectively.
internal information: INETWORK_CLOSE, INETWORK_NEWCLIENT, INETWORK_QUITCLIENT, INETWORK_CLIENTSINFO, INETWORK_PING or INETWORK_ERROR
user data with INETWORK_DATA,INETWORK_DATAVALIDATED or INETWORK_DATADENIED
Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
unsigned char CRM32Pro_INetwork::SendData ( char *  buff,
int  size,
char  isquery = 1 
)

Send data to server using a blocking method.

If you are on Authoritative Server Mode you have two ways of sending data:
- by default, the sent data will be evaluated by CoreServer to decide if refused the data or to send it to all clients.
- the sent data will bypass the CoreServer as if we were on Non-Authoritative Server Mode.
On Non-Authoritative Server Mode, the data will be always sent to all clients.

Parameters:
buff pointer to your data
size size in bytes of your data
isquery it only has sense when you are on Authoritative Server Mode.
By default is 1 and means that the data will be evaluated by CoreServer callback.
Any other value will bypass the CoreServer callback.
Returns:
0 Failed. Next ReceiveData() will return an INETWORK_ERROR
1 Ok
Examples:
Example10_NetChat.cpp, and Example11_NetChat2.cpp.
void CRM32Pro_INetwork::SetCoreServerCallback ( int(*)(void *data, int size)  myCoreServer  ) 

Set a callback function to hook into server thread to evaluate the sent data.

If you use a callback function, the INetwork will work on Authoritative Server Mode.
But if you dont set it or set it to NULL, the INetwork will work on Non-Authoritative Server Mode.
The code of this function will be executed on the server thread so keep this in mind.

Parameters:
myCoreServer your callback function. It takes a pointer to the sent data and its size. A safe method is always check that size is equal to your sent struct data.
It has to return 0 when the sent data is evaluated to denied so the data will not sent to all clients.
And when the data is evaluated to validated, it has to return 1.
On both cases, the source client will be notified with the denied(INETWORK_DATADENIED) or validated(INETWORK_DATAVALIDATED) signal
Any other value will do nothing.
Examples:
Example11_NetChat2.cpp.
void CRM32Pro_INetwork::SetTimeOut ( int  ms  ) 

Set the connection timeout.

By default, the timeout is set to 2000ms

Parameters:
ms desired timeout in milliseconds. Minimum is 500ms.

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

Generated on Mon Dec 21 17:04:40 2009 for CRM32Pro SDK v5.00 by  doxygen 1.6.1