net.Socket 类
- 继承自: <stream.Duplex>
此类是 TCP 套接字或流式 IPC 端点(在 Windows 上使用命名管道,否则使用 Unix 域套接字)的抽象。
它也是 EventEmitter
。
net.Socket
可以由用户创建并直接用于与服务器交互。
例如,通过 net.createConnection()
返回它,因此用户可以使用它与服务器对话。
它也可以由 Node.js 创建并在接收到连接时传给用户。
例如,它被传给在 net.Server
上触发的 'connection'
事件的监听器,因此用户可以使用它与客户端进行交互。
- Extends: <stream.Duplex>
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
.
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.
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.