request.socket
添加于:v0.3.0
对底层套接字的引用。通常用户不想访问此属性。特别是,由于协议解析器附加到套接字的方式,套接字不会发出 'readable'
事件。
const http = require('node:http');
const options = {
host: 'www.google.com',
};
const req = http.get(options);
req.end();
req.once('response', (res) => {
const ip = req.socket.localAddress;
const port = req.socket.localPort;
console.log(`Your IP address is ${ip} and your source port is ${port}.`);
// Consume response object
});
此属性保证是 <net.Socket> 类的实例,它是 <stream.Duplex> 的子类,除非用户指定了 <net.Socket> 以外的套接字类型。
相关用法
- Node.js request.socket用法及代码示例
- Node.js http.ClientRequest request.setHeader(name, value)用法及代码示例
- Node.js http2.Http2ServerRequest request.url用法及代码示例
- Node.js http.ClientRequest request.getHeaders()用法及代码示例
- Node.js http2.Http2ServerRequest request.headers用法及代码示例
- Node.js request.writableEnded用法及代码示例
- Node.js http.ClientRequest request.getHeaderNames()用法及代码示例
- Node.js http.ClientRequest request.removeHeader(name)用法及代码示例
- Node.js http.ClientRequest request.getHeader(name)用法及代码示例
- Node.js http.ClientRequest request.reusedSocket用法及代码示例
- Node.js http2.Http2ServerRequest request.rawHeaders用法及代码示例
- Node.js http.ClientRequest request.hasHeader(name)用法及代码示例
- Node.js http.ClientRequest request.getRawHeaderNames()用法及代码示例
- Node.js require.cache用法及代码示例
- Node.js require.main用法及代码示例
- Node.js require.extensions用法及代码示例
- Node.js require(id)用法及代码示例
- Node.js http.ServerResponse response.statusCode用法及代码示例
- Node.js readStream.isRaw用法及代码示例
- Node.js response.writeContinue()用法及代码示例
- Node.js http2.Http2ServerResponse response.removeHeader(name)用法及代码示例
- Node.js response.removeHeader()用法及代码示例
- Node.js http.ServerResponse response.getHeaderNames()用法及代码示例
- Node.js http2.Http2ServerResponse response.hasHeader(name)用法及代码示例
- Node.js http.ServerResponse response.removeHeader(name)用法及代码示例
注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 request.socket。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。