Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ruby0x1/2216619 to your computer and use it in GitHub Desktop.
Save ruby0x1/2216619 to your computer and use it in GitHub Desktop.
Multi-player games in HTML5 : Client Side Socket.io
<!DOCTYPE html>
<html>
<head>
<title> Real time multi-player games with HTML5</title>
<style type="text/css">
html , body {
background: #212121;
color: #fff;
margin: 0;
padding: 0;
}
#canvas {
position: absolute;
left: 0; right: 0; top: 0; bottom: 0;
margin: auto;
}
</style>
<!-- Notice the URL, this is handled by socket.io on the server automatically, via express -->
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<!-- This will create a connection to socket.io, and print the user serverid that we sent from the server side. -->
<script type="text/javascript">
//This is all that needs
var socket = io.connect('/');
//Now we can listen for that event
socket.on('onConnect', function( data ) {
//Note that the data is the object we sent from the server, as is. So we can assume its property for now.
console.log( 'Connected successfully to the socket.io server. My server side ID is ' + data.serverid );
});
</script>
</head>
<body>
<canvas id="canvas"> </canvas>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment