-
-
Save NathanGRomano/17cc26d0eb82dadea8fb to your computer and use it in GitHub Desktop.
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
//Server | |
var express = require('express'); | |
var fs = require('fs'); | |
var app = express(); | |
var server = require('http').createServer(app).listen(5000); | |
var bus = require('bus.io')(server); | |
//you don't have to listen to connection event unless you like | |
bus.io().on('connection', function(socket) { | |
console.log(socket.id); | |
//this will send the "Here is my bus', not a "Message" | |
socket.emit('echo', 'HERE IS MY BUS'); | |
//try this to send a "Message' | |
bus.message().i(socket.id).did('echo').what('HeERE is MY BUS').to(socket.id) | |
}); | |
app.get('/home', function(req, res){ | |
var file = fs.createReadStream('./index.html'); | |
file.pipe(res); | |
}); | |
//==================================== | |
///Client | |
<script type="text/javascript" src="/socket.io/socket.io.js"></script> | |
<script> | |
var client = io.connect(); | |
client.on('connect', function () { | |
// client.emit('echo', 'Hello, Bus.io!'); | |
}); | |
client.on('echo', function (who, what) { | |
//argumetns == ["HERE IS MY BUS"] | |
document.body.innerHTML += '<h1>'+what+'</h1>'; | |
}); | |
</script> |
sounds good and worked too.. but i did not understand whats with handling the data through lot of functions .. any specifics to that..?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This brings an idea to my mind. Wrap the socket.io socket
emit()
function so it actually triggers amessage
to the client.