Created
November 18, 2011 08:32
-
-
Save honjo2/1375906 to your computer and use it in GitHub Desktop.
[JavaScript] socket.ioを使ったwsサーバを使う
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> | |
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js'></script> | |
<script src='http://beta.node-ninja.com/socket.io/socket.io.js'></script> | |
<script> | |
$(function() { | |
var socket = io.connect('http://beta.node-ninja.com/', { port: 80} ); | |
socket.on('msg push', function(data) { | |
var $li = $('<li>').text(data); | |
$('#display').append($li); | |
}); | |
$('#ok').click(function() { | |
socket.emit('msg send', $('#msg').val()); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<form onSubmit="return false"> | |
<input id="msg" type="text"></input> | |
<input id="ok" type="submit" value="ok"></input> | |
</form> | |
<ul id="display"></ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment