Functions and Directives

Function SocketCreate() Professional

Creates a new socket and binds it to a given port.

SocketCreate( [<nSocketType>]  , ;
              <nPort>          , ;
              [<cLocalAddress>], ;
              [<lReuseAddress>], ;
              [@<nError>]        ) --> nSocket
Constants from the file SOCKET.CH must be used for this parameter:
Type of socket to create
Constant Description
SOCK_STREAM *) TCP stream socket
SOCK_DGRAM UDP datagram socket
  1. default
This is the numeric port number on the local computer to bind the socket to.
The local address is specified with a character string containing the host name or its IP address in dotted octet notation. If the application does not care what address is assigned to the socket, it may not provide this parameter. In this case the #define constant INADDR_ANY is used for <cLocalAddress>.
The default value for this parameter is .F. (false). When it is set to .T. (true) the socket may reuse the local address if it is already used by another socket.
If this parameter is passed by reference to the function, it gets assigned a numeric error code when the function fails. #define constants beginning with WSAE are available in the file SOCKET.CH to identify an error condition.

The function returns a numeric socket descriptor on success. If a socket cannot be created, the value of the #define constant INVALID_SOCKET is returned.


This function is used on the server side of a communication channel. It creates a socket and binds it to the specified address and port, which is equivalent to calling SocketNew() and SocketBind(). The bound socket is then used to listen to or to accept incoming communication requests.


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.