Open Tcp Server
 
Opens a listening TCP server socket and binds it to a file number.

Syntax

Declare Function Open Tcp Server ( options As String, As [#]filenumber As Long ) As Long

Usage

result = Open Tcp Server( options[,] As [#]filenumber )
Open Tcp Server options As [#]filenumber

Parameters

options
A comma-separated string describing the listening socket.
filenumber
The file number to bind to the server socket.

Return Value

Returns zero (0) on success, or a non-zero error code on failure.

Description

Open Tcp Server creates a listening TCP socket. The server file number is passed to Tcp Accept to accept incoming connections. The accepted client receives its own file number and can then be read from or written to using normal file I/O statements.

The options string accepts:
    • host=name-or-address, optional bind address
    • port=number, required
    • backlog=count, optional listen backlog, default 16
    • timeout=milliseconds, optional socket timeout

Server file numbers are not used for data transfer. Use Tcp Accept and then read or write the returned client file number.

Example

See examples/network/opentcp/http-server.bas and examples/network/opentcp/two-connections-selftest.bas.

Platform Differences

  • TCP support is not available on all targets. Programs that need to be portable should use target defines such as FB_DOS, FB_JS, and FB_XBOX where appropriate.

Differences from QB

  • New to FreeBASIC.

See also