| 
      
       | 
    
  
    | MXAddPort | 
    C
      NetProg Library  | 
   
  
    | 
      
     | 
   
 
 
 
      
  
    #include
      "mx.h"
      
        
           | 
           | 
         
        
           | 
          int        MXAddPort (MX*
            pmx, int port, int protocol) | 
         
       
     | 
   
 
      
 
 
  
    | Parameters | 
    Description | 
   
  
  
          | pmx  | 
          the
            MX manager | 
   
  
  
          | port  | 
          the
            port listening number  | 
   
  
  
          | protocol  | 
          the
            protocol used for this port | 
   
  
 
 
 
      This function adds a listening port allowing the application to
      accept connections on this port. The  protocol indicated in the function
      parameter is set for all
      connections on this  port 
The protocols supported are : 
  
    | IP  | 
    client | 
    server | 
    Connection | 
    Dialog | 
   
  
    | TCP | 
    yes | 
    yes | 
    IP_PROTO_TCP | 
    TCP | 
   
  
    | FTP | 
    yes | 
    no | 
    IP_PROTO_FTP | 
    FTP | 
   
  
    | HTTP | 
    yes | 
    no | 
    IP_PROTO_HTTP | 
    HTTP | 
   
  
    | SMTP | 
    yes | 
    no | 
    IP_PROTO_SMTP | 
    SMTP | 
   
  
    | POP | 
    yes | 
    no | 
    IP_PROTO_POP | 
    POP | 
   
  
    | DNS | 
    yes | 
    no | 
    IP_PROTO_DNS | 
    DNS | 
   
  
    | DG | 
    yes | 
    yes | 
    IP_PROTO_DG | 
    USER_DEFINED | 
   
 
For example , if an application
wants to write an FTP server, it adds the protocol IPPROTO_FTP on the port 21,
and write the callbacks related to the message classes of the predefined FTP
Dialog class 
  
    Return
      Values : -1 if error else > 0  
       | 
   
 
 
 
 
 
  
    | Example
      :
       int OnConnect (MXCom*
      pcom, void* appfield) 
      { 
        if (MXGetPort  (pcom) != 8080)  return 1; 
        printf ("===> Nbr connection opened= %d\n", ++NbOpen1);  
        MXAddComCallBack  (pcom->MX,
      pcom, HTTP_SYS, "Request", MXONRECV, RecvRequest, NULL);  
        return 1; 
      } 
       
       
      int main(int argc, char* argv[]) 
      { 
       
        MX mx; 
        
        MXInit (&mx, MXSERVER, NULL, NULL, 0,
      NULL); 
        MXAddPort (&mx, 8080,
      IPPROTO_HTTP); 
        MXAddGeneralConnectCallBack (&mx,
      MXONCONNECT, OnConnect, &mx); 
        MXDispatchEvents (&mx, 0); 
        MXEnd (&mx); 
      } 
       
       
       
     | 
   
 
         | 
      |