• hmm it makes sense, but when I execute the code and send over something along the lines of console.log("hi"); the loopback wont trigger the ws.send(msg); to send me back hi I'm not sure if I just misunderstood the concept.

    My understanding is that LoopbackA and LoopbackB are connected, data sent to one comes out the other one. In this manner, if I set console to LoopbackA, and then write my ws incoming command the following function should work.

    I've been testing with console.log("Hello"); from my ws server and I expect Hello back. I know the ws stuff is working fine, so it's probably that i miscoded the loopbacks.

    LoopbackA.setConsole();
    
    var host = "192.168.1.103";
    var WebSocket = require("ws");
    var ws = new WebSocket(host, {
      path: '/',
      port: 8080, // default is 80
      protocol: "echo-protocol", // websocket protocol name (default is none)
      protocolVersion: 13, // websocket protocol version, default is 13
      origin: 'Espruino',
      keepAlive: 60,
      headers: {
        some: 'header',
        'ultimate-question': 42
      } // websocket headers to be used e.g. for auth (default is none)
    });
    
    ws.on('open', function() {
      console.log("Connected to server");
      ws.send("esp:Connected");
    });
    
    ws.on('message', function(msg) {
      console.log(msg);
      var command = new Function(msg);
      LoopbackA.write(command());
      });
    
    
    LoopbackB.on('data',function(msg){
     ws.send(msg);
    });
    
About

Avatar for Esper @Esper started