通过Node.js上的代理的TCP套接字客户端 [英] TCP socket client through proxy on nodejs

查看:98
本文介绍了通过Node.js上的代理的TCP套接字客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将TCP套接字连接到smtp服务器.是否可以通过Node.js上的代理服务器进行连接?是否有可用的npm模块?我什么都找不到.

I need to make tcp socket connection to smtp server. Is it possible to connect through proxy server on nodejs? Is there any npm modules available to use? I couldn't find any at all.

var net = require('net');

var HOST = '127.0.0.1';
var PORT = 6969;

var client = new net.Socket();
client.connect(PORT, HOST, function() {
    console.log('CONNECTED TO: ' + HOST + ':' + PORT);
    client.write('I am here!');
});

// Add a 'data' event handler for the client socket
// data is what the server sent to this socket
client.on('data', function(data) {

    console.log('DATA: ' + data);

});

// Add a 'close' event handler for the client socket
client.on('close', function() {
    console.log('Connection closed');
});

推荐答案

net.sockettls.connectdgram没有代理支持.

将其与代理一起使用的最简单方法是将某些libc函数替换为proxychains或类似的东西.

The simplest way to use it with proxy is to replace some libc functions with proxychains or something similar.

var client = require('tls')
.connect(443, 'www.facebook.com', function() {
  console.log('connected');
  client.write('hello');
})
.on('data', function(data) {
  console.log('received', data.toString());
})
.on('close', function() {
  console.log('closed');
});

代理链节点fit.js

proxychains node fit.js

connected
received HTTP/1.1 400 Bad Request
...
closed

这篇关于通过Node.js上的代理的TCP套接字客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆