net.Socket 类


这个类是 TCP 或 UNIX Socket 的抽象(在Windows上使用命名管道,而UNIX使用域套接字)。一个net.Socket也是一个duplex stream,所以它能被读或写,并且它也是一个EventEmitter

net.Socket可以被用户创建并直接与server通信。举个例子,它是通过net.createConnection()返回的,所以用户可以使用它来与server通信。

当一个连接被接收时,它也能被Node.js创建并传递给用户。比如,它是通过监听在一个net.Server上的'connection'事件触发而获得的,那么用户可以使用它来与客户端通信。

This class is an abstraction of a TCP socket or a streaming IPC endpoint (uses named pipes on Windows, and UNIX domain sockets otherwise). A net.Socket is also a duplex stream, so it can be both readable and writable, and 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.