net.createConnection(port[, host][, connectListener])
port
<number> 套接字应该连接的端口号。会传给socket.connect(port[, host][, connectListener])
。host
<string> 套接字应该连接的主机名。会传给socket.connect(port[, host][, connectListener])
。默认值:'localhost'
。connectListener
<Function>net.createConnection()
的常见参数,在初始化套接字时对'connect'
事件的单次监听器,会传给socket.connect(port[, host][, connectListener])
。- 返回: <net.Socket> 用于开启连接的新创建的套接字。
初始化一个 TCP 连接。
这个函数用默认配置创建一个新的 net.Socket
,然后 socket.connect(port[, host][, connectListener])
初始化一个连接,并返回开启连接的那个 net.Socket
。
port
<number> Port the socket should connect to. Will be passed tosocket.connect(port[, host][, connectListener])
.host
<string> Host the socket should connect to. Will be passed tosocket.connect(port[, host][, connectListener])
. Default:'localhost'
.connectListener
<Function> Common parameter of thenet.createConnection()
functions, an "once" listener for the'connect'
event on the initiating socket. Will be passed tosocket.connect(port[, host][, connectListener])
.- Returns: <net.Socket> The newly created socket used to start the connection.
Initiates a TCP connection.
This function creates a new net.Socket
with all options set to default,
immediately initiates connection with
socket.connect(port[, host][, connectListener])
,
then returns the net.Socket
that starts the connection.