SocketTools .NET Edition

HttpServer.Start Method (String, Int32, String, Int32)

Start listening for client connections on the specified IP address and port number.

[Visual Basic]
Overloads Public Function Start( _
   ByVal localAddress As String, _
   ByVal localPort As Integer, _
   ByVal rootDirectory As String, _
   ByVal maxClients As Integer _
) As Boolean
[C#]
public bool Start(
   string localAddress,
   int localPort,
   string rootDirectory,
   int maxClients
);

Parameters

localAddress
A string which specifies the local hostname or IP address address that the server should be bound to. If this parameter is an empty string, then an appropriate address will automatically be used. If a specific address is used, the server will only accept client connections on the network interface that is bound to that address.
localPort
An integer that specifies the port number the server should use to listen for client connections. If a value of zero is specified, the server will use the standard port number 80 to listen for connections, or port 443 if the server is configured to use implicit TLS. The port number used by the application must be unique and multiple instances of a server cannot use the same port number. It is recommended that a port number greater than 5000 be used for private, application-specific implementations.
rootDirectory
A string that specifies the path to the root directory for the server. If this value is an empty string, the server will use the current working directory as the root directory.
maxClients
An integer value that specifies the maximum number of clients that may connect to the server.

Return Value

A boolean value which specifies if the server was started. A return value of true specifies that the server has been successfully started. If an error occurs, the method returns false and the application should check the value of the LastError property to determine the cause of the failure

Remarks

The Start method begins listening for client connections on the specified local address and port number. The server is started in its own thread and manages the client sessions independently of the calling thread.

To listen for connections on any suitable IPv4 interface, specify the special dotted-quad address "0.0.0.0". You can accept connections from clients using either IPv4 or IPv6 on the same socket by specifying the special IPv6 address "::0", however this is only supported on Windows 7 SP1 and Windows Server 2008 R2 or later platforms. If no local address is specified, then the server will only listen for connections from clients using IPv4. This behavior is by design for backwards compatibility with systems that do not have an IPv6 TCP/IP stack installed.

It is recommended that you always specify an absolute path for the server root directory, either by passing the full pathname as an argument to this method or by setting the Directory property. If the path includes environment variables surrounded by percent (%) symbols, they will be automatically expanded.

If you have configured the server to permit clients to upload files, you must ensure that your application has permission to create files in the directory that you specify. A recommended location for the server root directory would be a subdirectory of the %ALLUSERSPROFILE% directory. Using the environment variable ensures that your server will work correctly on different versions of Windows. If the root directory does not exist at the time that the server is started, it will be created.

See Also

HttpServer Class | SocketTools Namespace | HttpServer.Start Overload List