-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
createServer.js
49 lines (40 loc) · 1.37 KB
/
createServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import socks5 from '../src/socks5.js';
const server = socks5.createServer();
// start listening!
server.listen(1080);
server.on('handshake', function (socket) {
console.log();
console.log('------------------------------------------------------------');
console.log('new socks5 client from %s:%d', socket.remoteAddress, socket.remotePort);
});
// When a reqest arrives for a remote destination
server.on('proxyConnect', function (info, destination) {
console.log('connected to remote server at %s:%d', info.address, info.port);
destination.on('data', function (data) {
console.log(data.length);
});
});
server.on('proxyData', function (data) {
console.log(data.length);
});
// When an error occurs connecting to remote destination
server.on('proxyError', function (err) {
console.error('unable to connect to remote server');
console.error(err);
});
// When a request for a remote destination ends
server.on('proxyDisconnect', function (originInfo, destinationInfo, hadError) {
console.log(
'client %s:%d request has disconnected from remote server at %s:%d with %serror',
originInfo.address,
originInfo.port,
destinationInfo.address,
destinationInfo.port,
hadError ? '' : 'no ');
});
// When a proxy connection ends
server.on('proxyEnd', function (response, args) {
console.log('socket closed with code %d', response);
console.log(args);
console.log();
});