Skip to content

Instantly share code, notes, and snippets.

@stannehill
stannehill / blogpost-socketio-frontend-2
Created July 29, 2013 19:42
The last portion of the frontend code for socket.io blog post.
$(function () {
$('#target').click(function () {
$('#target').animate({top: '-200', opacity: 0.1}, 3000, function () {
socket.emit('volley', {'text': 'Shot made to server...'});
});
});
});
@stannehill
stannehill / blogpost-socketio-frontend1
Created July 29, 2013 17:30
First chunk of code for frontend of socket.io blog post.
var socket = io.connect('http://localhost:4000');
socket.on('connect', function () {
socket.on('return', function (data) {
$('#target').animate({top: '500', opacity: 1}, 3000);
});
socket.on('player', function(data){
if(data.player !== 0){
$('#target').css({"top": '-220px',"opacity": "0.1"});
}
@stannehill
stannehill / blogpost-socketio-backend-part3
Last active December 20, 2015 09:09
The third portion of the frontend code for the socket.io blog tutorial.
var playernum = 0;
io.sockets.on('connection', function (socket) {
console.log('connected successfully...');
playernum === 1 ? playernum = 0 : playernum++;
socket.emit('player', {'player': playernum});
socket.on('volley', function (input) {
socket.broadcast.emit('return', {'data': 1});
@stannehill
stannehill / blogpost-socketio-backend-part2
Created July 29, 2013 15:42
second portion of the code for the backend of the socket.io tutorial
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
@stannehill
stannehill / blogpost-socketio-frontend-part1
Created July 29, 2013 15:35
The initial chunk of code from the backend.
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs');
app.listen(4000);
@stannehill
stannehill / blogpost-socketio-frontend
Created July 29, 2013 15:13
Frontend code for socket.io blog post
<!DOCTYPE html>
<html>
<head>
<title>socket.io Test</title>
<style>
html {
background: url('http://166.78.51.174/woodfloor.png') no-repeat 0 0 scroll;
background-color: #0C0C0C;
background-size: 100% 100%;
height: 100%;
@stannehill
stannehill / blogpost-socketio-backend
Last active December 20, 2015 08:59
Backend code for socket.io blog post
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs');
app.listen(4000);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {