Skip to content

Instantly share code, notes, and snippets.

@NathanGRomano
Forked from gs-akhan/gist:e326f678578946cde0c6
Last active August 29, 2015 14:02
Show Gist options
  • Save NathanGRomano/17cc26d0eb82dadea8fb to your computer and use it in GitHub Desktop.
Save NathanGRomano/17cc26d0eb82dadea8fb to your computer and use it in GitHub Desktop.
//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>
@NathanGRomano
Copy link
Author

This brings an idea to my mind. Wrap the socket.io socket emit() function so it actually triggers a message to the client.

@gs-akhan
Copy link

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