Created
April 3, 2012 15:07
-
-
Save Jxck/2292777 to your computer and use it in GitHub Desktop.
simple socket.io server
This file contains 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 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
<html> | |
<head> | |
<script type="text/javascript" src="/socket.io/socket.io.js"></script> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<script type="text/javascript" src="sample.js"></script> | |
</head> | |
<body> | |
<input type="text" id="name"></input> | |
<input type="button" id="ok" value="ok"></input> | |
<ul id="display"></ul> | |
</body> | |
</html> |
This file contains 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
{ | |
"author": "Jxck", | |
"name": "socket-io-session", | |
"version": "0.0.0", | |
"repository": { | |
"url": "" | |
}, | |
"main": "server.js", | |
"engines": { | |
"node": "*" | |
}, | |
"dependencies": { | |
"socket.io": "*", | |
"connect": "*" | |
}, | |
"devDependencies": {} | |
} |
This file contains 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
$(function() { | |
var socket = io.connect(); | |
socket.on('connect', function() { | |
console.log('connected'); | |
$('#ok').click(function() { | |
var val = $('#name').val(); | |
socket.emit('msg send', val); | |
}); | |
socket.on('msg push', function(data) { | |
$li = $('<li>').text(data); | |
$('#display').append($li); | |
}); | |
}); | |
}); |
This file contains 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 connect = require('connect') | |
, io = require('socket.io') | |
; | |
var server = connect() | |
.use(connect.static(__dirname + '/public')) | |
.listen(3000); | |
io = io.listen(server); | |
io.sockets.on('connection', function(socket) { | |
socket.on('msg send', function(data) { | |
console.log(data); | |
io.sockets.emit('msg push', data); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment