-
-
Save dshaw/1268318 to your computer and use it in GitHub Desktop.
trouble getting socket.io to work in node
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
<title>Testing Socket.io</title></head> | |
<body><h1>Testing Socket.io</h1> | |
<p id="msg">connecting...</p> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> | |
<script src="/socket.io/socket.io.js"></script> | |
<script> | |
var socket = io.connect(); | |
var socketIoEvents = ['connect', 'connecting', 'connect_failed', 'message', 'close', 'disconnect', 'reconnect', 'reconnecting', 'reconnect_failed']; | |
for (var i in socketIoEvents) { | |
var event = socketIoEvents[i]; | |
socket.on(event, function () { console.log(event, arguments) }); | |
} | |
socket.on("news", function(data, successFn) { | |
$("#msg").html("connected! " + JSON.stringify(data)); | |
successFn("connected!"); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
{ | |
"name": "getify-wepuzzleit" | |
, "version": "0.0.1" | |
, "dependencies": { | |
"connect" : "1.7.1" | |
, "socket.io" : "0.8.4" | |
} | |
, "main": "./server.js" | |
, "engines": { "node": "~0.4.0" } | |
} |
This file contains hidden or 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
web: node server.js |
This file contains hidden or 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 connect = require('connect'), | |
app = connect.createServer(connect.static(__dirname)), | |
io = require('socket.io').listen(app), | |
port = process.env.PORT || 80 | |
; | |
app.listen(port); | |
io.configure(function(){ | |
io.enable('browser client minification'); // send minified client | |
io.enable('browser client etag'); // apply etag caching logic based on version number | |
// io.set('log level', 1); // reduce logging | |
io.set("transports", ["xhr-polling"]); | |
io.set("polling duration", 10); | |
}); | |
io.sockets.on('connection', function (socket) { | |
console.log("connection established!"); | |
//socket.on('my other event', function (data) { | |
// console.log("DATA:"+data); | |
//}); | |
socket.emit('news', { hello: 'world' }, function(data) { | |
console.log("received:"+data); | |
}); | |
}); |
100% less Connect.
Put back Connect. Inlined blobs of html are just painful.
Setup for Heroku. http://devcenter.heroku.com/articles/using-socket-io-with-node-js-on-heroku
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
npm install
sudo node server