Method _Stdio._port()->bind()
- Method
bind
int
bind(int
|string
port
,void
|function
(:void
)accept_callback
,void
|string
ip
,void
|string
reuse_port
)- Description
Opens a socket and binds it to port number on the local machine. If the second argument is present, the socket is set to nonblocking and the callback funcition is called whenever something connects to it. The callback will receive the id for this port as argument and should typically call accept to establish a connection.
If the optional argument
ip
is given, bind will try to bind to an interface with that host name or IP number. Omitting this will bind to all available IPv4 addresses; specifying "::" will bind to all IPv4 and IPv6 addresses.If the OS supports TCP_FASTOPEN it is enabled automatically.
If the OS supports SO_REUSEPORT it is enabled if the fourth argument is true.
- Returns
1 is returned on success, zero on failure. errno provides further details about the error in the latter case.
- See also