类:net.Socket
¥Class: net.Socket
-
¥Extends: <stream.Duplex>
此类是 TCP 套接字或流式 IPC 端点的抽象(在 Windows 上使用命名管道,否则使用 Unix 域套接字)。它也是 EventEmitter
。
¥This class is an abstraction of a TCP socket or a streaming IPC endpoint
(uses named pipes on Windows, and Unix domain sockets otherwise). It is also
an EventEmitter
.
net.Socket
可以由用户创建并直接用于与服务器交互。例如,它由 net.createConnection()
返回,因此用户可以使用它与服务器对话。
¥A net.Socket
can be created by the user and used directly to interact with
a server. For example, it is returned by net.createConnection()
,
so the user can use it to talk to the server.
它也可以由 Node.js 创建并在收到连接时传递给用户。例如,它被传递给 net.Server
上触发的 'connection'
事件的监听器,因此用户可以使用它与客户端进行交互。
¥It can also be created by Node.js and passed to the user when a connection
is received. For example, it is passed to the listeners of a
'connection'
event emitted on a net.Server
, so the user can use
it to interact with the client.