socket.io
socket.io copied to clipboard
Socket.IO connection between two apps
Hi,
Recently I was working to display server side logs to the client with socket.io and successfully done it now I have to do another thing with socket.io which is to display the logs of another application. For example App 1 is running and it displaying its log to the browser and now I want App 1 should also display the log of App2.
Here is my code which I did so far do display App1 Logs on the browser.
app.js
var app = express()
,server = require('http').Server(app)
,io = require('socket.io')(server)
Tail = require('tail').Tail;
server.listen(8080);
io.sockets.once('connection', function(socket) {
tail = new Tail("log.log"); // file to stream
tail.on('line', function(data) {
return io.sockets.emit('new-data', {
channel: 'stdout',
value: data
});
});
});
client.ejs
// creates socket on page load
$(function() {
var socket = null;
var streamer = null;
var socket = io.connect('http://localhost:6002');
streamer = $('p');
socket.on('new-data', function(data) {
var newLine = $('<span id="line">' + data.value + '</span></br>');
streamer.append(newLine);
});
});
</script>
<body>
<p> </p>
</body>
Above code works fine to display the logs of app1, to display app2 logs do I need to create another socket.io connection ? If yes then how ?
Thank You,
Waqas Ahmed