|  Developer
Updated on November 14, 2021

connect()

  • Establishes a connection to a remote side with a specified address. It’s an async call, when connection has been established, an event or gets sent to a set events handler.
  • Throw an exception if something local went wrong.
  • Both IPv4 and IPv6 along with a host name can be used as a remote address.
  • Once connection has been established there’s no way to change its type (TCP, UDP) and an address it’s connected to.
Edit
  • params: address (table), options (int) [optional].

Structure of an address parameter:

				
					{
    "ip": "string",
    "port": "string"
    "connection_type": "string"
}				
			
  • return: connection handle (int).
Edit
				
					require "network"

handle = network.connect( { ip = "127.0.0.1", port = "6010", connection_type = "TCP" } )
if not handle then
   print( "fail to connect" )
end