Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

KServer.h File Reference

Server Management functions. More...

#include "ktypes.h"
#include "KSocket.h"
#include "KServerSocket.h"
#include "KIntList.h"
#include "KStrList.h"

Typedefs

typedef _KServer KServer
 Server structure.
typedef KInt32kfunc_server_callbak )(KSocket *pSocket, KPtr pUserData)
 Declaration of the functions that should be called after server connexion. The given socket is correctly initialized and the function should not destroy it.

Functions

KTL_API KServerKServer_create (const KUInt16 iPort, const KUInt16 iMaxConn, kfunc_server_callbak *fCallBack)
 Creates a server.
KTL_API KBool KServer_launch (KServer *pServer, KPtr pUserData)
 Starts the server.
KTL_API KBool KServer_stop (KServer *pServer)
 Stops the server.
KTL_API void KServer_delete (KServer **pServer)
 Deletes a KServer structure.
KTL_API KServerSocketKServer_getServerSocket (KServer *pServer)
 Gets the KServerSocket structure associated to a server.
KTL_API KBool KServer_getStats (KServer *pServer, KUInt64 *pCnx, KUInt64 *pEndOk, KUInt64 *pEndBad)
 Returns statistics about server.
KTL_API KBool KServer_getConnectedSockets (KServer *pServer, KStrList **lIDs, KBoolList **lStates)
 Gets the connected sockets.


Detailed Description

Server Management functions.

Example of use for functions KServer and KSocket :

 // The server callback
 KInt32 socket_server_callback (KSocket* pSocket, KPtr pUserData) {
    KUChar* pBuffer = knull;
    KUInt64 iReadBytes = 0;
    KString sText = knull;

    KSocket_send (pSocket, "Hello socket client!", 20);
    KSocket_waitStatus (pSocket, KSOK_STATUS_AVAILABLE_DATA);
    KSocket_readAll (pSocket, &pBuffer, &iReadBytes);

    sText = KString_new (iReadBytes);
    k_memcpy (sText, pBuffer, iReadBytes);
    k_print_std ("Received message from client : \"%s\"\n", sText);

    k_free (sText);
    k_free (pBuffer); 
    return 1;
 }

 // The main function
 KInt main (KInt argc, KString argv[]) {
    KServer* pServer = knull;

    pServer = KServer_create (3000, 100, &socket_server_callback);
    KServer_launch (pServer, knull);
    k_sleep (60);
    KServer_stop (pServer);
    KServer_delete (&pServer);

    return 0;
 }

Version:
KToolLib-1.0
Author:
Fabien Gallot
Date:
20/08/2009
Note:
Copyright © 2008-2010 iKlax Media SAS (www.iklaxmedia.com). All rights reserved.

Typedef Documentation

typedef KInt32( kfunc_server_callbak)(KSocket *pSocket, KPtr pUserData)
 

Declaration of the functions that should be called after server connexion. The given socket is correctly initialized and the function should not destroy it.

Parameters:
pSocket the pointer to the socket that corresponds to the last server connexion
pUserData the pointer to the user's data
Returns:
an integer not used for the moment


Function Documentation

KTL_API KServer* KServer_create const KUInt16  iPort,
const KUInt16  iMaxConn,
kfunc_server_callbak fCallBack
 

Creates a server.

Parameters:
iPort an integral number that identifies the port for the server connexion
iMaxConn an integral number that represents the maximum number of simultaneous server connexion
fCallBack the pointeur to a function called for each successful connexion of a socket on the server
Returns:
the pointer to the KServer structure correctly initialized if successful otherwise knull

KTL_API void KServer_delete KServer **  pServer  ) 
 

Deletes a KServer structure.

Parameters:
pServer the pointers to the KServer structure to be deleted

KTL_API KBool KServer_getConnectedSockets KServer pServer,
KStrList **  lIDs,
KBoolList **  lStates
 

Gets the connected sockets.

Parameters:
pServer the pointer to the KServer structure
lIDs the pointers to the list of strings that stores the IDs of the connected sockets
lStates the pointers to the list of booleans that stores the states of the connected sockets
Returns:
ktrue if successful otherwise kfalse

KTL_API KServerSocket* KServer_getServerSocket KServer pServer  ) 
 

Gets the KServerSocket structure associated to a server.

The returned structure should be destroyed by using the KServer_delete function

Parameters:
pServer the pointer to the KServer structure
Returns:
the pointer to the KServerSocket structure if successful otherwise knull

KTL_API KBool KServer_getStats KServer pServer,
KUInt64 pCnx,
KUInt64 pEndOk,
KUInt64 pEndBad
 

Returns statistics about server.

Parameters:
pServer the pointer to the KServer structure
pCnx a pointer to an 64 bit integer. This value will contain the number of current connexion
pEndOk a pointer to an 64 bit integer. This value will contain the number of connexion which close with success
pEndBad a pointer to an 64 bit integer. This value will contain the number of connexion which close with errors
Returns:
ktrue if successful otherwise kfalse

KTL_API KBool KServer_launch KServer pServer,
KPtr  pUserData
 

Starts the server.

Parameters:
pServer the pointer to the KServer structure
pUserData the pointer to data used as a parameter for the function called at socket connexion
Returns:
ktrue if successful otherwise kfalse

KTL_API KBool KServer_stop KServer pServer  ) 
 

Stops the server.

Stops the sockets connected and the listening of sockets connexion.

Parameters:
pServer the pointer to the KServer structure
Returns:
ktrue if successful otherwise kfalse


Generated on Tue Mar 9 10:49:30 2010 for iKlax Tools Library (KToolLib) by doxygen 1.3.8