daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Aug 18th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var io = require('socket.io').listen(8080),
  2.     net = require('net'),
  3.     carrier = require('carrier'),
  4.     CRLF = '\r\n';
  5.    
  6. io.sockets.on('connection', function(socket) {
  7.     socket.on('tcp', function(host, port) {
  8.         var sock = net.createConnection(port, host);
  9.        
  10.         sock.on('connect', function(err) {
  11.             if (err)
  12.                 return socket.emit('error', err);
  13.                
  14.             socket.emit('connected');
  15.             carrier.carry(sock, function(line) {
  16.                 socket.emit('line', line);
  17.             });
  18.            
  19.             socket.on('write', function(data) {
  20.                 if (!sock)
  21.                   return socket.emit('error', 'No socket');
  22.                  
  23.                 sock.write(data + CRLF);
  24.             });
  25.            
  26.             socket.on('end', function() {
  27.                 sock.end();
  28.             });
  29.         });
  30.     });
  31. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top