I can't get the client-side events to fire, please see the code/explanation:
Okay, so I got this working(I think)
Client-side code:
<script src="./Socket.IO/socket.io.js"></script>
<script>
io.setPath('./Socket.IO/');
var socket = new io.Socket('jayz.danstanhope.webfactional.com', { 'port': 80 });
socket.on('connect', function () {
alert('connect');
});
socket.on('message', function (msg) {
alert('message' + msg);
});
socket.on('close', function () {
alert('close');
});
socket.on('disconnect', function () {
alert('disconnect');
});
socket.connect();
</script>
Server-side code:
var sys = require("sys")
, fs = require("fs")
, path = require("path")
, http = require("http");
var io = require('/home/danstanhope/webapps/htdocs/Socket.IO-node');
var server = http.createServer(function (req, res) {
//your normal server code
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('Hello world');
res.end();
});
server.listen(26970);
server = io.listen(server);
server.on('connection', function(client){
sys.log('client connected');
});
When I refresh the page in Chrome I can see logs being written in Shell.
Here's what I see:
danstanhope@web146 htdocs]$ node server.js
9 Aug 19:19:37 - socket.io ready - accepting connections
9 Aug 19:19:40 - Initializing client with transport "websocket"
9 Aug 19:19:40 - Client 21789167495444417 connected
9 Aug 19:19:40 - client connected
9 Aug 19:19:40 - Client 21789167495444417 disconnected
The only issue now is getting any of those javascript socket alerts to fire.
Also, this error is showing up in Chrome:
Bad Upgrade header: Server: nginx
Date: Wed, 11 Aug 2010 23:06:06 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Upgrade: WebSocket
Any ideas on how to fix a "bad header"?
Thanks, Dan