Last active
March 21, 2016 20:06
-
-
Save vesse/ed1691160084aa7c15bb to your computer and use it in GitHub Desktop.
socket.io namespace emit http://stackoverflow.com/questions/36138248/
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> | |
<script src='http://localhost:3000/socket.io/socket.io.js'></script> | |
<script> | |
var socket = io.connect('http://localhost:3000/nsa'); | |
socket.emit('request', { | |
msg : 'appA user is requesting something' | |
}); | |
socket.on('incoming-request', function(data) { | |
// This does not happen because server emits to nsb | |
console.log('Oops, received data', data); | |
}); | |
</script> | |
</head> | |
</html> |
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> | |
<script src='http://localhost:3000/socket.io/socket.io.js'></script> | |
<script> | |
var socket = io.connect('http://localhost:3000/nsb'); | |
socket.on('incoming-request', function(data) { | |
console.log('Received data', data); | |
}); | |
</script> | |
</head> | |
</html> |
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
var sockio = require('socket.io'), | |
server = require('http').createServer(); | |
var io = new sockio(server), | |
ns_a = io.of('/nsa'), | |
ns_b = io.of('/nsb'); | |
ns_a.on('connection', function(socket) { | |
console.log('Someone joined NS A'); | |
socket.on('request', function(data) { | |
ns_b.emit('incoming-request', { repark : data }); | |
}); | |
}); | |
ns_b.on('connection', function(socket) { | |
console.log('Someone joined NS B'); | |
}); | |
server.listen(3000, function() { | |
console.log('Server is listening on 3000'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment