title: Node-Red: Use config node - Every "client" node sends the same msg
body: <p>Following <a href="https://stackoverflow.com/questions/38403245/node-red-create-server-and-share-input">this</a> question I have managed to get a config-node working and share the server to respective client nodes (similar to the mqtt node)</p>
  
  <p>The basic idea is as follows:</p>
  
  <ul>
  <li>Establish an UDP listening socket as config-node</li>
  <li>Parse incoming messages in client nodes, returning the payload depending on the channel of the node</li>
  <li>The socket always receives all channels encoded in 14 bytes but each client node shall only react on the channel for which it is responsible for</li>
  </ul>
  
  <p>Here is what I have so far and please bear with me. It took me a lot trial and error (well more errors) to get to this as I'm just learning to code.</p>
  
  <pre><code>    function TACMIServer(n) {
      RED.nodes.createNode(this, n);
      this.host = n.host;
      this.port = n.port;
      this.cmiIP = n.cmiIP;
      this.CoEConnection = {};
  
      var node = this;
  
      node.CoEConnectionInitialize = function (handler) {
          if (node.CoEConnection.isConnected) {
              logInfo(node, 'Socket already listening on ' + this.host + ':' + this.port);
              if (handler &amp;&amp; (typeof handler === 'function')) {
                  handler(node.CoEConnection);
              }
              return node.CoEConnection;
          }
          node.CoEConnection.socket = dgram.createSocket('udp4');
  
          node.CoEConnection.socket.on('listening', function () {
              var address = node.CoEConnection.socket.address();
              logInfo(node, 'UDP Server listening on ' + address.address + ":" + address.port);
              //logInfo(node, 'CoEConnection1: ' + util.inspect(node.CoEConnection, { showHidden: true, depth: null }));
          });
  
          node.CoEConnection.socket.bind({
              address: this.host,
              port: this.port,
              exclusive: true
          });
  
          node.setMaxListeners(0);
  
          node.CoEConnection.isConnected = true;
  
          if (handler &amp;&amp; (typeof handler === 'function')) {
              handler(node.CoEConnection);
          }
          return node.CoEConnection;
  
      };
  
      node.on('close', function () {
          node.CoEConnection.socket.close();
          node.CoEConnection.isConnected = false;
      });
      }
      RED.nodes.registerType("cmiCoE-server", TACMIServer);
  
  
  
  
      function TACoEInAnalogue(n) {
      RED.nodes.createNode(this, n);
  
      this.port = n.port;
      this.host = n.host;
      this.channel = n.channel;
      this.connection = null;
      var serverConfig = RED.nodes.getNode(n.server);
  
      var node = this;
  
  
      serverConfig.CoEConnectionInitialize(function (connection) {
          node.connection = connection;
          if (node.connection.isConnected) {
              node.connection.socket.on('message', function (message, remote) {
                  node.connection.bb = new ByteBuffer.fromBase64(message, 1, 0);
                  node.connection.bb.toBinary();
                  node.connection.CoEdata = decodeCoE(node.connection.bb);
                  ReadCoEdata(node.connection.CoEdata);
                  //logInfo(node, 'CoEData: ' + util.inspect(node.connection, { showHidden: true, depth: null }));
              });
          } else {
              //todo: handle not connected
          }
  
          function ReadCoEdata(data) {
              var msg = {};
              switch (data.type) {
              case "digital":
                  msg.channel = parseInt(node.channel);
                  logInfo(node, 'digitalValues: ' + data.digitalValues.printDebug());
                  logInfo(node, 'Channel: ' + node.channel);
                  msg.payload = getDigitalChannel(msg.channel, data.digitalValues);
  
                  msg.pdo = data.PDO;
                  msg.node = data.CANnode;
                  node.status({
                      fill: "green",
                      shape: "dot",
                      text: "Ch: " + node.channel + "D"
                  });
                  logInfo(node, 'Node: ' + node + " msg: " + msg.payload);
                  node.send(msg);
                  break;
              case "analog":
                  var result = null;
                  msg.channel = parseInt(node.channel);
                  result = getAnalogueChannel(msg.channel, data.analogValues);
                  msg.uname = result.name;
                  msg.unit = result.unit;
                  msg.payload = result.value;
                  logInfo(node, 'Node: ' + node + " msg: " + msg.payload);
                  node.send(msg);
                  break;
              }
          }
  
          node.on('close', function () {
              node.connection.close();
          });
  
      });
      }        
      RED.nodes.registerType("cmiCoE-analogue-in", TACoEInAnalogue);
  </code></pre>
  
  <p>Now my problem is that each client node is sending the same data as msg.</p>
  
  <p>How can I make a client node A only responsible for a certain part of the socket message and a client node B for another part?</p>