Skip to content

Instantly share code, notes, and snippets.

@erayarslan
Last active February 12, 2016 15:11
Show Gist options
  • Select an option

  • Save erayarslan/d3ef5b10969ca4e5be4e to your computer and use it in GitHub Desktop.

Select an option

Save erayarslan/d3ef5b10969ca4e5be4e to your computer and use it in GitHub Desktop.
spachcock ws example
var WebSocket = require('ws');
var Spachcock = require("spachcock");
var ws = new WebSocket('ws://echo.websocket.org');
var $ = new Spachcock();
$.route("/:first/:second", function (req, res) {
console.log(req.params);
});
$.response = ws.send;
Spachcock.prototype.parser = function (data) {
return data;
};
$.listen();
ws.on('open', function() {
ws.send('/hello/world');
});
ws.on('message', function(data, flags) {
$.handle(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment