Open Tcp
Opens a TCP client connection and binds it to a file number.
Syntax
`
Declare Function Open Tcp ( options As String, As [#]filenumber As Long ) As Long
`
Usage
`
result = Open Tcp( options[,] As [#]filenumber )
Open Tcp options As [#]filenumber
`
Parameters
`options`
A comma-separated string describing the connection.
`filenumber`
The file number to bind to the connected socket.
Return Value
Returns zero (`0`) on success, or a non-zero error code on failure.
Description
`Open Tcp` connects to a TCP server and exposes the socket through FreeBASIC's normal file I/O statements. Once opened, the file number can be used with `Print #`, `Line Input #`, `Input()`, `Get #`, and `Put #`.
The options string accepts:

- `host=name-or-address`, required for client connections
- `port=number`, required
- `timeout=milliseconds`, optional socket timeout

Unknown options are ignored so that future TCP options can be added without breaking existing programs.
For sockets, `EOF` means that no byte is currently available to read. Use `Eoc` to test whether the peer has closed the connection.
Example
See `examples/network/opentcp/http-get.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

- `Open Tcp Server`
- `Tcp Accept`
- `Eoc`
- `Open`