Created
March 27, 2012 14:58
-
-
Save ruby0x1/2216619 to your computer and use it in GitHub Desktop.
Multi-player games in HTML5 : Client Side Socket.io
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> | |
<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