C Examples
MXAddGeneralConnectCallBack C NetProg Library 

#include "mx.h"
int MXAddGeneralConnectCallBack (MX* pmx, BYTE mode, int (*funct)(MXCom* pcom, void* applicationfield), void* applicationfield)

Parameters Description
pmx  the MX manager
mode  the event that triggers the callback 
funct  the function to call when any connection is closed or opened
applicationfield  Programmer-specified data sent to the callback function

Description : 

This function adds a callback to the MX manager. The callback is triggered when any connection of the application is opened or closed depending on the mode parameter. If an error occurs on a connection belonging to the application the connection is automatically closed by the MX manager and the callback of the ONCLOSED mode is called

The mode parmeter can be : MXONCONNECT, MXONCLOSE

applicationfield specifies the argument that is to be passed to the specified procedure when it is invoked

Return Values : if error returns -1 else returns a value > 0

See Also : MXRemoveGeneralConnectCallback, MXAddConnectCallback, MXRemoveConnectCallback 

Example :

int TCPOnConnect (MXCom* pcom, void* apfield)
  if (MXGetPort (pcom) == 8080)
     MXAddComCallBack (pcom->MX, pcom, TCP_SYS, "Stream", MXONRECV, TCPStreamReply, NULL);

int TCPOnClose (MXCom* pcom, void* apfield)

int main ()
  MX mx;

  MXInit (&mx, MXSERVER, NULL, NULL, 0, NULL);
  MXAddPort (&mx, 8080, IPPROTO_TCP);
  MXAddGeneralConnectCallBack (&mx, MXONCONNECT, TCPOnConnect, NULL);
  MXAddGeneralConnectCallBack (&mx, MXONCLOSE, TCPOnClose, NULL);

  MXDispatchEvents (&mx, 0);

  MXEnd (&mx);