Skip to content

Instantly share code, notes, and snippets.

@paradoja
Created June 3, 2012 20:07
Show Gist options
  • Save paradoja/2864836 to your computer and use it in GitHub Desktop.
Save paradoja/2864836 to your computer and use it in GitHub Desktop.
Playing with node
<html>
<head>
<title> ¡Hola! </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
var server = io.connect('http://localhost:8080');
document.onkeypress = manda;
function manda(event) {
if (event.keyCode == 38)
server.emit('flecha_arriba', "hola");
}
server.on('vale', function (mensaje, otro_mensaje) {
alert(mensaje);
alert(otro_mensaje)
} );
</script>
</head>
<body>
Hola desde el body de index.
</body>
fs = require 'fs'
socket = require 'socket.io'
express = require 'express'
app = express.createServer()
io = socket.listen app
app.get '/', (request, response) ->
index = fs.createReadStream 'index.html'
console.log 'alguien entra'
index.pipe response
app.get '/socket.io/socket.io.js', (request, response) ->
js = fs.createReadStream 'node_modules/socket.io/lib/socket.io.js'
console.log 'Mandamos el js'
js.pipe response
io.sockets.on 'connection', (client) ->
client.on 'flecha_arriba', () ->
console.log 'le dieron a la flecha para arriba'
client.emit 'vale', 'pepito', 'otro'
app.listen 8080
console.log 'Servidor abierto en 8080'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment