I have a very simple node server which listens to a socket and transmits the messages to all clients (flex). While this works for clients publishing the message, I want to be able to publish messages also through a web API. Is it possible?
var express = require('express');
var app = express();
var io = require('socket.io').listen(server, {
flashPolicyServer: true,
transports: ['flashsocket', 'websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']});
io.sockets.on('connection', function(client) {
client.on('invalidation', function(message) {
client.emit('message', message); // send message to sender
client.broadcast.emit('message', message); // send message to everyone else but the sender
});
client.on('disconnect', function(client) {});
});
I forgot to say that the web API is in PHP. Anyways, I've found that socket.io uses a very specific socket, hence I couldn't just use any socket from PHP to get to it. There is a library called Elephant which is fairly easy to use and works well.