OpenNetworkConnection()

Syntax

Connection = OpenNetworkConnection(ServerName$, Port [, Mode [, TimeOut [, LocalIP$ [, LocalPort]]]])
Description
Opens a network connection to the specified server.

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.
Mode (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
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()

Supported OS

All

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