Functions and Directives

Function SocketNew() Professional

Creates a new, unbound socket.

SocketNew( [<nAddressFamily>], ;
           [<nSocketType>]   , ;
           [<nProtocol>]     , ;
           [@<nError>]         ) --> nSocket
This parameter specifies the adress family to which the socket belongs to. Windows only supports the #define constant AF_INET as value, which is the default.
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
Optionally, the protocol to be used for communication can be specified with this parameter. Most Windows sockets applications, however, will use the value 0 for this parameter. Other values can be obtained with the SocketGetProtoBy..() functions.
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 new socket descriptor on success, or the value of INVALID_SOCKET on error.


The function allocates resources for a new, unbound socket of a given type and prepares it for the specified protocol. If a protocol is not defined, the default for the specified socket type is used. When the socket is created for connection-oriented communication (i.e. SOCK_STREAM), it must be in connected state before any data can be transferred on it with SocketSend() or SocketRecv(). A connection to another socket is created with SocketConnect(). The connection must be interrupted with SocketClose() when the communication is complete.


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.