类:net.Socket


🌐 Class: net.Socket

这个类是 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.