Created
March 23, 2013 06:38
-
-
Save timoxley/5226701 to your computer and use it in GitHub Desktop.
Uncaught Error: Unexpected "\u0000" at position 0 in state START
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = require('url') | |
var websocket = require('websocket-stream') | |
var engine = require('voxel-engine') | |
var duplexEmitter = require('duplex-emitter') | |
console.log('starting', 1) | |
var socket = websocket('ws://' + url.parse(window.location.href).host) | |
var emitter = duplexEmitter(socket) | |
window.emitter = emitter | |
window.socket = socket | |
emitter.on('hello', function() { | |
console.log('HI') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path') | |
var http = require('http') | |
var ecstatic = require('ecstatic') | |
var WebSocketServer = require('ws').Server | |
var websocket = require('websocket-stream') | |
var duplexEmitter = require('duplex-emitter') | |
var uuid = require('hat') | |
var server = http.createServer(ecstatic(path.join(__dirname))) | |
var wss = new WebSocketServer({server: server}) | |
wss.on('connection', function(ws) { | |
// turn 'raw' websocket into a stream | |
var stream = websocket(ws) | |
var emitter = duplexEmitter(stream) | |
console.log('connected') | |
emitter.emit('hello', {hi: true}) | |
}) | |
server.listen(3000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment