最近想自己写一个简单的科学上网工具 想法是这样的: 主要分为 3 各部分,
浏览器根据 socks5 协议发送数据给本地 tcp proxy,本地 tcp proxy 加密数据,发送给远程 tcp proxy,远程 tcp proxy 解密数据发给 socks 服务器代替浏览器做请求。
本地测试没有问题,但是一旦把 tcp proxy 和 socks 服务器真的部署到另一台机器上,就不行了。 会一直报错:
// 代码大概长是这样
// encrypt 和 decrypt 就是简单的 AES 对称加密: https://github.com/timqian/viti/blob/master/src/utils/encrypt.js
// repo: https://github.com/timqian/viti/
net.createServer({allowHalfOpen: true}, localsocket => {
// connect to remote tcp server
const remotesocket = new net.Socket();
remotesocket.connect(remotePort, remoteHost);
localsocket.on('data', data => {
encrypt(data, password);
remotesocket.write(data)
});
remotesocket.on('data', data => {
decrypt(data, password);
localsocket.write(data);
});
}
## 报的错误
# local
Error: This socket is closed
at Socket._writeGeneric (net.js:732:18)
at Socket._write (net.js:792:8)
at doWrite (_stream_writable.js:388:12)
at writeOrBuffer (_stream_writable.js:374:5)
at Socket.Writable.write (_stream_writable.js:291:11)
at Socket.write (net.js:710:40)
at Socket.remotesocket.on.data (/Users/timqian/Documents/viti/src/utils/getEncryptedProxy.js:20:23)
at Socket.emit (events.js:159:13)
at addChunk (_stream_readable.js:265:12)
at readableAddChunk (_stream_readable.js:252:11)
# remote
{ Error: This socket has been ended by the other party
at Socket.writeAfterFIN [as write] (net.js:365:12)
at Socket.localsocket.on.data (/usr/lib/node_modules/viti/src/utils/getEncryptedProxy.js:12:25)
at Socket.emit (events.js:159:13)
at addChunk (_stream_readable.js:265:12)
at readableAddChunk (_stream_readable.js:252:11)
at Socket.Readable.push (_stream_readable.js:209:10)
at TCP.onread (net.js:608:20) code: 'EPIPE' }
即使两个机器都在国内也是不行 不知道是代码问题还是墙的作用
1
frozenway 2017-12-19 14:06:57 +08:00
这不是 shadow 袜的工作原理吗?
|
3
onsale 2017-12-19 14:58:54 +08:00 via Android
onplus/shadowsocks-websocket-python
|