Socket.constructor(host, port, [ family ]) constructor


The Socket constructor returns a Socket value representing a Windows TCP socket to be bound to a specific IP address or hostname on the given port number. In case of hostname, a DNS query is sent to be resolved to a valid IP of the given family.

Parameters

host

A string representing an IP address (family is autodetected) or a hostname (IP is autoresolved to the given family)

port

The port number the Socket will be bound to.

family

An optional string to specify the address family when resolving the provided hostname.

  • "ipv4" : an IPv4 address will be used when resolving the hostname (default)
  • "ipv6" : an IPv6 address will be used when resolving the hostname

Example

local net = require "net" -- valid local sock = net.Socket("www.google.com", 80) -- valid sock = net.Socket("smtp.google.com", 80) -- error : 'http:\www.google.com' is an URL not a hostname sock = net.Socket("http:\\www.google.com", 80)