How to use net - 10 common examples

To help you get started, we’ve selected a few net examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wuchangming / node-mitmproxy / src / mitmproxy / createConnectHandler.js View on Github external
function connect (req, cltSocket, head, hostname, port) {
    // tunneling https
    var proxySocket = net.connect(port, hostname, () => {
        cltSocket.write('HTTP/1.1 200 Connection Established\r\n' +
        'Proxy-agent: node-mitmproxy\r\n' +
        '\r\n');
        proxySocket.write(head);
        proxySocket.pipe(cltSocket);
        cltSocket.pipe(proxySocket);
    });
    proxySocket.on('error', (e) => {
        console.log(colors.red(e));
    });
    return proxySocket;
}
github DeutscheSoft / AES70.js / tests / device.js View on Github external
constructor(target) {
    this.server = net.createServer((connection) => {
      const socket = new net.Socket();
      socket.connect(target);
      const fragmenter = new FragmentationConnection(connection, socket);
    });

    this.server.listen();
  }
github graalvm / graaljs / test / parallel / test-net-better-error-messages-listen.js View on Github external
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');

const server = net.createServer(common.mustNotCall());
server.listen(1, '1.1.1.1', common.mustNotCall());
server.on('error', common.mustCall(function(e) {
  assert.strictEqual(e.address, '1.1.1.1');
  assert.strictEqual(e.port, 1);
  assert.strictEqual(e.syscall, 'listen');
}));
github graalvm / graaljs / test / parallel / test-net-better-error-messages-listen-path.js View on Github external
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const fp = '/blah/fadfa';
const server = net.createServer(common.mustNotCall());
server.listen(fp, common.mustNotCall());
server.on('error', common.mustCall(function(e) {
  assert.strictEqual(e.address, fp);
}));
github CodeChain-io / codechain-test-helper-js / src / p2pLayer.ts View on Github external
constructor(ip: string, port: number, networkId: string) {
        this.socket = new Socket();
        this.ip = ip;
        this.port = port;
        this.arrivedExtensionMessage = [];
        this.tcpBuffer = Buffer.alloc(0);
        this.genesisHash = new H256("0000000000000000000000000000000000000000000000000000000000000000");
        this.recentHeaderNonce = new U256(0);
        this.recentBodyNonce = new U256(0);
        this.log = false;
        this.networkId = networkId;
        this.localKey = EC.genKeyPair();
    }
github stream-labs / streamlabs-obs / test / helpers / api-client.ts View on Github external
connect() {
    if (this.socket) this.socket.destroy();

    this.socket = new net.Socket();
    this.bindListeners();

    this.log('connecting...');
    this.connectionStatus = 'pending';

    return new Promise((resolve, reject) => {
      this.resolveConnection = resolve;
      this.rejectConnection = reject;
      this.socket.connect(PIPE_PATH);
    });
  }
github mabels / Sashimi / sashimi.js View on Github external
var client_connect = function(server, stream) {
    console.log('Connect peer='+server.peer.host+":"+ server.peer.port+" my="+server.my.host+":"+ server.my.port+":"+server['no_output'])
    stream = net.createConnection(server.peer.port, server.peer.host, { bind: server.my });   
    status.connections.client.connects++;
    streamer(stream, {
      closed: function() {
                setTimeout(function() { 
                  client_connect(server, stream); 
                }, 1000);
              }
    }, server)
  }
  servers.forEach(function(server) {
github sahilchaddha / yeelight-platform / src / device.js View on Github external
connect() {
    try {
      this.forceDisconnect = false
      this.socket = new net.Socket()
      this.bindSocket()
      this.socket.connect({ host: this.device.host, port: this.device.port }, () => {
        this.didConnect()
        this.emit('connected')
      })
    } catch (err) {
      this.socketClosed(err)
    }
  }
github layr-team / Layr / utils / tcp.js View on Github external
const createServer = (port, host, connectionCallback, listenCallback) => {
    const server =  net.createServer(connectionCallback)
    
    server.listen(port, host, () => {
      listenCallback(server)
    })

    server.on('error', (err) => {throw err})
    return server;
  }
github daaku / nodejs-freeport / lib / freeport.js View on Github external
module.exports = function(cb) {
  var server = net.createServer()
    , port = 0
  server.on('listening', function() {
    port = server.address().port
    server.close()
  })
  server.on('close', function() {
    cb(null, port)
  })
  server.on('error', function(err) {
    cb(err, null)
  })
  server.listen(0, '127.0.0.1')
}

net

Globalizes the 'net' module functions

MIT
Latest version published 11 years ago

Package Health Score

50 / 100
Full package analysis