Skip to content

Instantly share code, notes, and snippets.

@odeke-em
Created December 13, 2015 03:05
Show Gist options
  • Save odeke-em/7bb8e8d9ab450e304691 to your computer and use it in GitHub Desktop.
Save odeke-em/7bb8e8d9ab450e304691 to your computer and use it in GitHub Desktop.
var tls = require('tls');
    var fs = require('fs');

    var options = {
      // These are necessary only if using the client certificate authentication
      key: fs.readFileSync('client-key.pem'),
      cert: fs.readFileSync('client-cert.pem'),

      // This is necessary only if the server uses the self-signed certificate
      ca: [ fs.readFileSync('server-cert.pem') ]
    };

    var socket = tls.connect(8000, options, function() {
      console.log('client connected',
                  socket.authorized ? 'authorized' : 'unauthorized');
      process.stdin.pipe(socket);
      process.stdin.resume();
    });
    socket.setEncoding('utf8');
    socket.on('data', function(data) {
      console.log(data);
    });
    socket.on('end', function() {
      server.close();
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment