I have designed this server to broadcast to all clients when it has to and broadcast to specific clients when it has to.
I started working on client code to connect to it based on the arguments set in there but i got a mixed up at the point when client A is supposed to connect when a message is meant for client A or client B needs to connect based on that argument.
Below is the server code. A client pseudo code will be appreciated. thanks
//send messages to game clients and forward to bay
var socket_cl = io.listen(server);
socket_cl.on('connection', function (client) {
client.on('message', function (data) {
broadcast(data); // broadcast to all clients
// OR
//search for kiosk / the right kiosk for machine which sent message
//to be forwarded bayboard client
//after this find the location of that kiosk and send
JSON.parse(data);
if (data.type == 'bb_message') {
var kiosk = readerEngine.getKiosk(client.request.socket.remoteAddress);
bayboard_location_map[kiosk.location_id].send(data.message);
}
socket.clients[id].send(data); //send message to bayclients
});
client.on('disconnect', function () {
console.log('Client Disconnected.');
});
I think you mean you want to send data to a particular client? Your server code looks like its going to do a lookup based on an id that you pass from the client?
Such that: