Skip to content

Instantly share code, notes, and snippets.

@timoxley
Created March 23, 2013 06:38
Show Gist options
  • Save timoxley/5226701 to your computer and use it in GitHub Desktop.
Save timoxley/5226701 to your computer and use it in GitHub Desktop.
Uncaught Error: Unexpected "\u0000" at position 0 in state START
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')
})
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