quick mockup mutli-client routing for socketio
Last active
May 27, 2016 15:07
-
-
Save adityabansod/2b83d4d8cc456fd7d4b821b229466a07 to your computer and use it in GitHub Desktop.
socket.io mockup
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
require('./client1') |
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
console.log('1'); | |
// Connect to server | |
var io = require('socket.io-client'); | |
var socket = io.connect('http://localhost:8080', {reconnect: true}); | |
console.log('2'); | |
socket.on('getAppointments', function() { | |
console.log(arguments) | |
console.log(socket.emit) | |
socket.emit('getAppointmentsCallback', 'callback from 1') | |
}) | |
// Add a connect listener | |
socket.on('connect', function(socket) { | |
console.log('Connected!'); | |
}); | |
console.log('3'); |
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
console.log('1'); | |
// Connect to server | |
var io = require('socket.io-client'); | |
var socket = io.connect('http://localhost:8080', {reconnect: true}); | |
console.log('2'); | |
socket.on('getAppointments', function() { | |
console.log(arguments) | |
console.log(socket.emit) | |
socket.emit('getAppointmentsCallback', 'callback from 222') | |
}) | |
// Add a connect listener | |
socket.on('connect', function(socket) { | |
console.log('Connected!'); | |
}); | |
console.log('3'); |
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
// Load requirements | |
var http = require('http'), | |
io = require('socket.io'); | |
// Create server & socket | |
var server = http.createServer(function(req, res) | |
{ | |
// Send HTML headers and message | |
res.writeHead(404, {'Content-Type': 'text/html'}); | |
res.end('<h1>Aw, snap! 404</h1>'); | |
}); | |
server.listen(8080); | |
io = io.listen(server); | |
// Add a connect listener | |
io.sockets.on('connection', function(socket) | |
{ | |
console.log('Client connected, sending getAppointments'); | |
socket.emit('getAppointments', {'asdf': socket.id}) | |
socket.on('getAppointmentsCallback', console.log) | |
console.log(socket.id) | |
// Disconnect listener | |
socket.on('disconnect', function() { | |
console.log('Client disconnected.'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment