Skip to content

Instantly share code, notes, and snippets.

@Pingolus
Last active August 29, 2015 14:25
Show Gist options
  • Save Pingolus/4e242f06aca1abb89b32 to your computer and use it in GitHub Desktop.
Save Pingolus/4e242f06aca1abb89b32 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Socket.io</title>
</head>
<body>
<h1>Exemple de tchat avec socket.io</h1>
<input type="text" id="nouveauMessage">
<input type="submit" id="envoyer" value="Envoyer le message">
<table id="tabMessages">
<thead>
<tr><th>Messages :</th></tr>
</thead>
</table>
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('server_ip:8080');
socket.on('messageGeneral', function(message) {
$("#tabMessages").append("<tr><td>" + message + "</td></tr>");
});
$("#envoyer").on("click", function() {
socket.emit('nouveauPost', $("#nouveauMessage").val());
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment