启动 Web、TCP、UDP 或 WebSocket 监听服务。
net.listen(config)
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| config | Object | 是 | 无 | 监听配置,type 必填,支持 web、tcp、udp、ws。 |
| 类型 | 说明 |
|---|---|
| WebServer/TcpServer/UdpSocket/WsServer | 按 type 返回对应服务句柄。 |
server = net.listen({type: 'tcp', bind: '127.0.0.1:0'}) result = server.type server.close() // 输出:tcp print result