Created
September 24, 2016 13:57
-
-
Save uorat/35023ff98c7e1e42973c804df9301a46 to your computer and use it in GitHub Desktop.
Sample client code for Socket.IO w/ ALB
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> | |
<title>hello node.js!</title> | |
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script src="https://your.domain.or.ip/socket.io/socket.io.js"></script> | |
<script> | |
$(document).ready(function(){ | |
var socket = io.connect('https://your.domain.or.ip'); | |
socket.on('connect', function() { | |
console.log("connect [sessid = " + socket.id + "]"); | |
}); | |
socket.on('message', function(data) { | |
console.log('data = ' + data.value); | |
$('div#comment').append('<div>' + data.value + ' [sessid = ' + data.sessid + ']</div>'); | |
}); | |
socket.on('disconnect', function() { console.log('exit !!'); }); | |
$(':button[name=buttonMsg]').click(function() { | |
var msg = $(':text[name=message]').val(); | |
socket.emit('message', { value: msg, sessid: socket.id }); | |
}); | |
$(':button[name=buttonDiscon]').click(function() { | |
var msg = "Disconnected [sessid = " + socket.id + "]"; | |
socket.emit('message', { value: msg, sessid: socket.id }); | |
socket.disconnect(); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<input type="text" name="message" value=""> | |
<input type="button" name="buttonMsg" value="send message"> | |
<input type="button" name="buttonDiscon" value="disconnect"> | |
<h1>comment</h1> | |
<div id="comment"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment