在做接口本地化代理时,遇到一个问题,就是如何使用nodejs模拟请求一个远程socket请求?
比如地址:wss://a.com:8080/b
var net = require('net')
var client= new net.Socket()
client.connect('8080','a.com')
client.addListener('data', function(data) {
console.log('data', data.toString())
})
但是后面的path /b 怎么办呢?
我改成下面这种方式,但是会报错
var net = require('net')
var client= new net.Socket()
client.connect('wss://a.com:8080/b')
client.addListener('data', function(data) {
console.log('data', data.toString())
})
Error: getaddrinfo ENOTFOUND wss://a.com:8080/b
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
我改成下面这种方式,也会报错
var net = require('net')
var client= new net.Socket()
client.connect({
path:'wss://a.com:8080/b'
})
client.addListener('data', function(data) {
console.log('data', data.toString())
})
net.Socket
是tcp/unix socket, 不是WebSocket