How do you create a socket in node with socket.io and emit to it.
The idea is that i am getting data from a twilio from the server and with this data i want to send it to an ios app
I Have tried
var server = require('http').Server(router);
var io = require('socket.io')(server);
router.post('/respond', function(req, res) {
var result_From;
var result_Digits;
res.header('Content-Type','text/xml').send(SAY_TO_USER);
result_From = req.body.From;
result_Digits = req.body.Digits;
console.log( result_From + " typed: " + result_Digits);
io.emit('values changed', 'data');
});
io.on('values changed', function(){
console.log('hello')
});
server.listen(8080);
what i want to do in that route is when a request comes in, it changes both result_Digits and result_From so i want to be able to emit a socket when the value changes so i can use it on a mac application.
Cheers
First, you need your clients to connect to your socket, usually in your client html document :
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect();
socket.on('values changed', function(values){
//do something with values
});
</script>
Then you can use in your app :
io.on('connection', function(socket){
socket.on('values changed', function(){
console.log('hello')
});
});