Slisten
Previous Topic  Next Topic 

Synopsis: 

       socket=Slisten(port)


Arguments:

       port - The port to listen on


Description:   This function returns a listening socket on the specified port.    Only one socket can be listening on a particular port at any one time and if a second call to Slisten() is made on the same port then it will return an error.          The socket returned by this function can be used in the Saccept() function to wait for inbound socket connections on the port.


For example:


       // Get a listening socket on port 5000

       Lsocket=Slisten(5000);


       // Loop waiting for inbound connections on this port

       while(1)

               Asocket=Saccept(Lsocket);

               // The above function will return -3 is there are no waiting inbound connections

               if(Asocket eq -3)                

                       sleep(1);

                       continue;   //  keep polling

               // Also check for error

               else if(Asocket < 0)

                       errlog("Error in Saccept():  err=", Asocket);

                       stop;

               // else we must have an inbound connection request...

               else

                       break;

               endif endif

       endwhile





Returns:    A socket for the inbound connection or a negative error code (in particular -3 indicates that there is no inbound connection waiting yet).