response.socket
-
类型:<net.Socket> | <tls.TLSSocket>
¥Type: <net.Socket> | <tls.TLSSocket>
返回 Proxy 对象,该对象充当 net.Socket(或 tls.TLSSocket),但应用了基于 HTTP/2 逻辑的获取器、设置器、以及方法。
¥Returns a Proxy object that acts as a net.Socket (or tls.TLSSocket) but
applies getters, setters, and methods based on HTTP/2 logic.
destroyed、readable 和 writable 属性将从 response.stream 检索并设置。
¥destroyed, readable, and writable properties will be retrieved from and
set on response.stream.
destroy, emit, end, on 和 once 方法将在 response.stream 上调用。
¥destroy, emit, end, on and once methods will be called on
response.stream.
setTimeout 方法将在 response.stream.session 上调用。
¥setTimeout method will be called on response.stream.session.
pause, read, resume, and write 将抛出错误代码为 ERR_HTTP2_NO_SOCKET_MANIPULATION。有关详细信息,请参阅 Http2Session 和套接字。
¥pause, read, resume, and write will throw an error with code
ERR_HTTP2_NO_SOCKET_MANIPULATION. See Http2Session and Sockets for
more information.
所有其他交互将直接路由到套接字。
¥All other interactions will be routed directly to the socket.
import { createServer } from 'node:http2';
const server = createServer((req, res) => {
const ip = req.socket.remoteAddress;
const port = req.socket.remotePort;
res.end(`Your IP address is ${ip} and your source port is ${port}.`);
}).listen(3000);const http2 = require('node:http2');
const server = http2.createServer((req, res) => {
const ip = req.socket.remoteAddress;
const port = req.socket.remotePort;
res.end(`Your IP address is ${ip} and your source port is ${port}.`);
}).listen(3000);