Created
November 10, 2011 14:49
-
-
Save kkestell/1355017 to your computer and use it in GitHub Desktop.
A Simple Chat Room with Node.js
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
<script src="/client/socket.io.js"></script> | |
<script> | |
$(document).ready(function() { | |
var socket = new io.Socket(null, {rememberTransport: false, port: 8080}); | |
socket.on('connect', function() { | |
socket.send('A client connected.'); | |
}); | |
socket.on('message', function(message) { | |
$('div#messages').html('<p>' + message + '</p>' + $('div#messages').html()); | |
}); | |
socket.on('disconnect', function() { | |
}); | |
socket.connect(); | |
$('input').keydown(function(event) { | |
if(event.keyCode === 13) { | |
socket.send($('input').val()); | |
$('input').val(''); | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<input type="text" style="width: 300px;" /> | |
<hr /> | |
<div id="messages" /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment