Skip to content

Instantly share code, notes, and snippets.

@edrex
Last active September 10, 2015 20:13
Show Gist options
  • Select an option

  • Save edrex/9a68bf01d833f26cf9aa to your computer and use it in GitHub Desktop.

Select an option

Save edrex/9a68bf01d833f26cf9aa to your computer and use it in GitHub Desktop.
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var net = require('net');
var socket = net.connect({
host: 'localhost',
port: 64080
});
socket.on('error', function (err) {
console.error(err);
});
socket.on('connect', function () {
console.log('Connected!');
});
socket.on('data', function (buffer) {
document.getElementById('output').innerHTML += buffer.toString();
});
socket.on('end', function () {
console.log('Socket closed.');
});
var ending = '\r\n';
var reqStr = 'GET /'+ending+'Host: google.com'+ending+ending;
document.getElementById('input').innerHTML = reqStr;
socket.write(reqStr);
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({net:[function(require,module,exports){},{}]},{},[]);var net=require("net");var socket=net.connect({host:"localhost",port:64080});socket.on("error",function(err){console.error(err)});socket.on("connect",function(){console.log("Connected!")});socket.on("data",function(buffer){document.getElementById("output").innerHTML+=buffer.toString()});socket.on("end",function(){console.log("Socket closed.")});var ending="\r\n";var reqStr="GET /"+ending+"Host: google.com"+ending+ending;document.getElementById("input").innerHTML=reqStr;socket.write(reqStr);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {}
}
<div id="output"></div>
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment