npm install
node ./index.js
Last active
August 29, 2015 14:09
-
-
Save kfigiela/ea6d82089f375c375aea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Socket.IO chat</title> | |
<style> | |
body, html { padding:0; margin: 0; font-family: monospace;} | |
#messages { list-style-type: none; margin: 0; padding: 0; } | |
#messages li { padding: 5px 10px; } | |
#messages li:nth-child(odd) { background: #eee; } | |
</style> | |
</head> | |
<body> | |
<ul id="messages"></ul> | |
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script> | |
<script src="http://code.jquery.com/jquery-1.11.1.js"></script> | |
<script> | |
var socket = io(":3000"); | |
socket.on('log', function(msg){ | |
$('#messages').append($('<li>').text(msg)); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('express')(); | |
var http = require('http').Server(app); | |
var io = require('socket.io')(http); | |
var spawn = require('child_process').spawn; | |
var tail = spawn("tail", ["-f", "/var/log/system.log"]) | |
app.get('/', function(req, res){ | |
res.sendfile(__dirname + '/index.html'); | |
}); | |
tail.stdout.on("data", function (data) { | |
io.emit('log', data.toString('utf-8')); | |
}); | |
io.on('connection', function(socket){ | |
console.log("Client connected") | |
}); | |
http.listen(3000, function(){ | |
console.log('listening on *:3000'); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "socket-chat-example", | |
"version": "0.0.1", | |
"description": "my first socket.io app", | |
"dependencies": { | |
"express": "4.3.1", | |
"socket.io": "1.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment