Created
August 27, 2014 08:38
-
-
Save companje/6f7763b9ea42c5cedc2c to your computer and use it in GitHub Desktop.
socketserver.js experiment
This file contains hidden or 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
| var socket = require('socket.io') | |
| var express = require('express') | |
| var app = express(); | |
| var http = require('http').Server(app); | |
| var io = require('socket.io')(http); | |
| var printer = { | |
| id: 0, | |
| name: "Ultimaker-F1A23B" | |
| } | |
| var networks = [ | |
| {ssid:"FabLab Amersfoort",secured:true}, | |
| {ssid:"VechtclubXL F1.19",secured:true}, | |
| {ssid:"sitecom",secured:false}, | |
| {ssid:"Ziggo23123",secured:true} | |
| ]; | |
| //default namespace | |
| io.on('connection', function(socket) { | |
| console.log('a user connected'); | |
| io.emit('info', printer); | |
| socket.on('getNetworks', function(cb) { | |
| cb(networks); | |
| }); | |
| socket.on('join', function(data,cb) { | |
| console.log("join:",data); | |
| //printer needs to register at the server or supply it's private code | |
| cb(); | |
| }) | |
| // setTimeout(function() { | |
| // console.log("emit: joined"); | |
| // socket.emit("joined",networks[0]); | |
| // },2500); | |
| socket.on('disconnect', function(){ | |
| console.log('user disconnected'); | |
| }); | |
| }); | |
| app.get('/', function(req, res){ | |
| res.send('Please connect using socket.io'); | |
| }); | |
| http.listen(8081, function(){ | |
| console.log('accesspoint listening on *:8081'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment