I have the following code:
/* WEB SERVER AND SOCKET */
var express = require("express");
var app = express();
var port = process.env.PORT || 3010;
var io = require('socket.io').listen(app.listen(port));
io.configure(function () {
io.set("transports", [
'websocket'
, 'xhr-polling'
, 'flashsocket'
, 'htmlfile'
, 'jsonp-polling'
]);
io.set("polling duration", 10);
});
/* TWITTER STUFF */
t.track('hashtag');
t.track('sometag');
t.on('tweet', function (tweet) {
console.log('Tweet received from ' + tweet.user.name + ' (@' + tweet.user.screen_name + '): ' + tweet.text);
io.sockets.emit('tweet', {
user: {
name: tweet.user.name,
screen_name: tweet.user.screen_name,
profile_pic: tweet.user.profile_image_url
},
text: tweet.text,
time: tweet.created_at,
photo: tweet.media.media_url
});
});
When running this, if I tweet using the hashtag, I get the log but no socket message is sent. Also, any following tweets do not do anything, suggesting that the emit function is hanging. In my log when starting the server, at the beginning I see:
info - socket.io started
info - FlashPolicyFileServer received an error event: listen EADDRINUSE
However, connections can still be made. Running netstat -tulpn | grep :3010
doesn't return anything, so I don't really get what the issue is. I'm running socket.io 0.9.16 and express 3.5.1.
change this line
var port = process.env.PORT || 3010;
to
var port =8080; // for testing