I am trying to set up Socket.IO but Im having trouble getting it to work..
I have followed these instructions to get a node server working which all went ok (I have used 127.0.0.1rather than the private ip address as everything is on the one server
I have then aded this to my nginx config:
location /socket-app {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
and restarted nginx
all the above is working as when I go to http://ift.tt/19PDkM9 I get "Hello World" printed on the screen.
So far so good!
Now for the socket.io setup
I used the code snippetes from Socket.IO in the "Using with Node http server" section replacing the port number with 8080:
app.js:
var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');
app.listen(8080);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
index.html:
<script src="http://ift.tt/1Abvuox"></script>">
<script>
var socket = io('http://example.com:8080');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
but in the console I am now getting:
[Log] socket.io-client:url parse http://example.com:8080 +0ms
[Log] socket.io-client new io instance for http://example.com:8080 +0ms
[Log] socket.io-client:manager readyState closed +0ms
[Log] socket.io-client:manager opening http://example.com:8080 +0ms
[Log] engine.io-client:socket creating transport "polling" +0ms
[Log] engine.io-client:polling polling +1ms
[Log] engine.io-client:polling-xhr xhr poll +1ms
[Log] engine.io-client:polling-xhr xhr open GET: http://ift.tt/1LmRIHq +0ms
[Log] engine.io-client:polling-xhr xhr data null +1ms
[Log] engine.io-client:socket setting transport polling +1ms
[Log] socket.io-client:manager connect attempt will timeout after 20000 +5ms
[Log] socket.io-client:manager readyState opening +1ms
then after a while i get this:
[Error] Failed to load resource: The request timed out. (socket.io, line 0) http://ift.tt/19PDmng
Have no idea why it is timing out..
Can anyone point me in the right direction?
i am using an ubuntu 14.04 server with forge (but this is not in a laravel setup)
Thanks, Dave
Aucun commentaire:
Enregistrer un commentaire