I'm running into issues with a very simple example of socket.io and
node.js hosted in heroku. I know heroku does not support websockets,
so i've configured socket.io to use long polling instead. Everything
works great when I am running a single web process in heroku.
> I start to see strange behavior when I scale to more than 1 web process
I see that my socket.io connection is doing a round robin between my
node processes, which is expected however it starts to error, the
connection becomes inconsistant and eventually get into a state where
the connection simple doesn't work anymore. Does anyone have
experience with this?
Sorry for the messy DOM work below.
SERVER:
---------------------------------------------
var express = require('express');
var app = express.createServer(express.logger());
var port = process.env.PORT || 3001;
app.listen(port);
app.use("/", express.static(__dirname + '/'));
var io = require('socket.io').listen(app);
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
io.sockets.on('connection', function (socket) {
socket.on('newmessage', function (data) {
console.log(data)
socket.broadcast.emit('chat', data);
socket.emit('chat', data); // just testing
});
});
CRUDE CLIENT
--------------------------------------------
<html>
<script src="/socket.io/socket.io.js"></script>
<body>
<input id="textInput" type=text>
<input type=button onClick="goClicked()" value="GO" />
<script>
var socket =
io.connect(window.document.location.protocol +
window.document.location.host);
socket.on('chat', function (data) {
var newP = document.createElement("p");
var txt = JSON.stringify(data);
var newT = document.createTextNode(txt);
newP.appendChild(newT);
var theBody =
document.getElementsByTagName('body')[0];
theBody.appendChild(newP);
});
function goClicked()
{
var textInput =
document.getElementById('textInput');
socket.emit('newmessage', textInput.value);
}
</script>
</body>
</html>
Here are the errors I start to see in the Chrome Console:
Uncaught TypeError: Property 'open' of object #<Transport> is not a
function
* I see lots and lots of these.
Any help or if anyone has an example of something that is working
across load blanced heroku processes, I'd love to see it.
Thanks,
--mm
--
You received this message because you are subscribed to the Google Groups
"Heroku" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/heroku?hl=en.