OpenNetworkConnection()

Syntax

Connection = OpenNetworkConnection(ServerName$, Port [, Flags [, TimeOut [, LocalIP$ [, LocalPort]]]])
Description
Opens a network connection to the specified server. To support TLS encryption, UseNetworkTLS() needs to be called before this command and a TLS flag needs to be specified.

Parameters

ServerName$ The server to connect to. This can be an IP address or a full name (ie: "127.0.0.1" or "ftp.home.net").
Port The port on the server to connect to.
Flags (optional) This can be one of the following values:
  #PB_Network_TCP: The connection will use the TCP network protocol (default)
  #PB_Network_UDP: The connection will use the UDP network protocol. The connection will not be
                   explicitly created, as UDP is a connectionless protocol, but it will add an 
                   entry in the PureBasic management stack and allow to send data via UDP using 
                   the regular SendNetworkData() (and related) functions.
combined with one of the following values (using the '|' operand):
  #PB_Network_IPv4: open the connection using IPv4 (default)
  #PB_Network_IPv6: open the connection using IPv6
combined with one of the following values (using the '|' operand):
  #PB_Network_NoTLS  : no encryption will be supported for this connection (default)
  #PB_Network_TLSv1  : all non-deprecated TLS protocols will be supported (currently v1.2 and v1.3)
  #PB_Network_TLSv1_0: TLS v1.0 protocol will be supported (warning, this protocol is deprecated for security reasons)
  #PB_Network_TLSv1_1: TLS v1.1 protocol will be supported (warning, this protocol is deprecated for security reasons)
  #PB_Network_TLSv1_2: TLS v1.2 protocol will be supported
  #PB_Network_TLSv1_3: TLS v1.3 protocol will be supported
TimeOut (optional) The maximum time (in milliseconds) before aborting the connection attempt. Usually, it shouldn't be set to a too low value (less than 5000 milliseconds), as initializing a connection over the net can take some time.
LocalIP$ (optional) The local IP address to bind the connection to.
LocalPort (optional) The local port to bind the connection to. By default a random local port is automatically chosen for the new connection, but it can be overridden with this parameter.

Return value

Returns the connection identifier for the opened connection if the connection was established correctly. If there was an error the result is zero.

See Also

NetworkClientEvent(), SendNetworkData(), ReceiveNetworkData(), CloseNetworkConnection(), UseNetworkTLS()

Supported OS

All

<- NextIPAddress() - Network Index - ReceiveNetworkData() ->