This command opens a TCP socket for reading or writing.
The TCP connection number to be opened. Up to 10 connections may be open at any time. The connection number identifies which TCP socket is being accessed. The connection number ranges from 1 to 10.
This string contains the host name or IP address of the remote TCP socket. The address$ is only used in the client mode and will be ignored in the server mode. In the server mode you may set this parameter to an empty string "".
This is the remote TCP port number.
This indicates if the socket should be opened in the client or server mode. mode$ may be "c" for client or "s" for server.
This is an optional parameter which specifies the timeout for opening a TCP socket. If not specified it defaults to 10 seconds. Timeout is in milliseconds. For infinite timeout set this value to 0.
This is an optional parameter which specifies the timeout for all read/write commands. If not specified it defaults to 10 seconds. For infinite timeout set this value to 0.
' Open a TCP socket in the server mode.
' Wait 60 seconds for connection.
TcpOpen 1, "", 1999, "s", 60000
Print "State: "; TcpGetState(1)
Print "error: "; TcpGetError$(1)
Print "IP: "; TcpGetAddr$(1)
if TcpGetState(1) <> 1 then
Print "Connection failed"
After a TcpOpen it is important to check if the open succeeded. All internet connections are subject to interruption at any time so check the TcpGetError$(n) after each TCP command you execute.