I installed on Rackspace with Ubuntu node.js with Socket.IO
When I tried a simple server application and tried to use a client request, I got "only static content" instead of manual jitter. In the browser in debugging, I see "Hello S ..." and on the server side:
info - socket.io started
debug - served static content /socket.io.js
debug - served static content /socket.io.js
I'm not sure where to start looking for the problem (the same script works in local development)
Why does node.js only serve static content and does not support handshaking?
Iptables allow port 8866: # iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all
ACCEPT all
ACCEPT tcp
ACCEPT tcp
ACCEPT tcp
DROP all
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp
Here is a simple socket-server.js server application:
var http = require('http'), io = require('socket.io');
var server = http.createServer(function(req, res){
res.writeHead(200,{ 'Content-Type': 'text/html' });
res.end('<h1>Hello Socket Lover!</h1>');
});
server.listen(8866);
var socket = io.listen(server);
socket.on('connection', function(client){
var interval = setInterval(function() {
client.send('This is a message from the server! ' + new Date().getTime());
},5000);
client.on('message',function(event){
console.log('Received message from client!',event);
});
client.on('disconnect',function(){
clearInterval(interval);
console.log('Server has disconnected');
});
});
Here is a simple client (SERVERDOMAIN replaced by a real domain):
<!DOCTYPE html>
<html>
<head>
<script src="http://SERVERDOMAIN:8866/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('SERVERDOMAIN:8866');
socket.on('connect',function() {
log('<span style="color:green;">Client has connected to the server!</span>');
});
socket.on('message',function(data) {
log('Received a message from the server: ' + data);
});
socket.on('disconnect',function() {
log('<span style="color:red;">The client has disconnected!</span>');
});
function sendMessageToServer(message) {
socket.send(message);
log('<span style="color:#888">Sending "' + message + '" to the server!</span>');
}
function log(message) {
var li = document.createElement('li');
li.innerHTML = message;
document.getElementById('message-list').appendChild(li);
}
</script>
</head>
<body>
<p>Messages will appear below (and in the console).</p><br />
<ul id="message-list"></ul>
<ul style="margin:20px 0 0 20px;">
<li>Type <code>socket.disconnect()</code> to disconnect</li>
<li>Type <code>socket.connect()</code> to reconnect</li>
<li>Type <code>sendMessageToServer('Your Message')</code> to send a message to the server</li>
</ul>
</body>
</html>