Skip to content

Instantly share code, notes, and snippets.

@YoshihitoAso
Created March 13, 2013 09:54
Show Gist options
  • Save YoshihitoAso/5150672 to your computer and use it in GitHub Desktop.
Save YoshihitoAso/5150672 to your computer and use it in GitHub Desktop.
[Node.js]Socket.ioのサンプルプログラム(client)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="http://xxx.xxx.xxx.xxx:1337/socket.io/socket.io.js"></script>
<script type="text/javascript">
$(function(){
var socket = io.connect('http://xxx.xxx.xxx.xxx:1337/');
socket.on('connect', function() {
$("#log").html($("#log").html() + "<br />" + 'connected');
socket.on('info', function (data) {
$("#log").html($("#log").html() + "<br />" + data.msg);
});
socket.on('msg', function(data){
$("#log").html($("#log").html() + "<br />" + "<b>" + data.msg + "</b>");
});
$("#send").click(function(){
var msg = $("#msg").val();
if(!msg){
alert("input your message");
return;
}
socket.emit('msg', msg);
});
});
});
</script>
<title>nodetest</title>
</head>
<body>
<input id="msg" type="text" style="width:400px;"></input>
<input id="send" type="button" value="send" /></br >
<div id="log" style="width:400px;height:400px;overflow:auto;border:1px solid #000000;"></div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment