#include "ktypes.h"
#include "KSocket.h"
#include "KServerSocket.h"
#include "KIntList.h"
#include "KStrList.h"
Typedefs | |
| typedef _KServer | KServer |
| Server structure. | |
| 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. | |
Functions | |
| KTL_API KServer * | KServer_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 KServerSocket * | KServer_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. | |
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; }
|
|
Declaration of the functions that should be called after server connexion. The given socket is correctly initialized and the function should not destroy it.
|
|
||||||||||||||||
|
Creates a server.
|
|
|
Deletes a KServer structure.
|
|
||||||||||||||||
|
Gets the connected sockets.
|
|
|
Gets the KServerSocket structure associated to a server. The returned structure should be destroyed by using the KServer_delete function
|
|
||||||||||||||||||||
|
Returns statistics about server.
|
|
||||||||||||
|
Starts the server.
|
|
|
Stops the server. Stops the sockets connected and the listening of sockets connexion.
|
1.3.8