title: Passing OSC messages between two computers over WAN via UDP and Node.js
body: <p>I'm trying to write some minimalist client-server code to pass OSC messages between two computers that are on different local networks. Specifically my end goal is to send and receive from MAX patches in Ableton, using MAX's UDPSend and UDPReceive functions, which simply listen on local ports. Here is the server code, that I have Ableton's OSC Send MIDI module send to. This correctly receives output from the first computer's MAX patch, some MIDI data from a channel.</p>
  
  <pre><code>var osc = require('osc-min'),
  dgram = require('dgram');
  var remotes = [];
  var FileReader = require('fs');
  
  // listen for OSC messages and print them to the console
  var udp = dgram.createSocket('udp4', function(msg, rinfo) {
    try {
      var oscmsg = osc.fromBuffer(msg);
      console.log(oscmsg);
      remotes.forEach(function(remote, index, array) {
          udp.send(msg, 0, oscmsg.length, 10000, remote);
          console.log('Sent OSC message to %s:%d', remote, 10000);
      });
    } catch (err) {
      console.log(err);
    }
  
  });
  
  FileReader.readFile('ips.txt', 'utf8', function(err, data) {
      // By lines
      var lines = data.split('\n');
      for(var line = 0; line &lt; lines.length; line++){
          remotes.push(lines[line]);
      }
  });
  
  udp.bind(9998);
  console.log('Listening for OSC messages on port 9998');
  </code></pre>
  
  <p>The server correctly gets an OSC message like this:</p>
  
  <pre><code>{ address: '/Note1',
  args: [ { type: 'integer', value: 60 } ],
  oscType: 'message' }
  </code></pre>
  
  <p>I then want to relay Computer 1's message to my remote server on port 9998 to the rest of the computers I have listening on port 10000. (The server is an Amazon EC2 Ubuntu instance.) The public IPs of these computers are in a file ips.txt.</p>
  
  <p>On the receiving computers (testing on Windows), I set up a Node client to receive data via its public IP and relay it to localhost so the MAX patch can see it. Thus, any messages sent to 10000 on this computer will be sent to 127.0.0.1:9999.</p>
  
  <pre><code>var osc = require('osc-min'),
      dgram = require('dgram'),
      remote;
  
  // listen for OSC messages and print them to the console
  var udp = dgram.createSocket('udp4', function(msg, rinfo) {
  
    try {
      var oscmsg = osc.fromBuffer(msg);
      console.log(oscmsg);
      send(msg);
    } catch (err) {
      console.log('Could not decode OSC message');
    }
  
  });
  
  function send(oscMessage) {
  
    udp.send(oscMessage, 0, oscMessage.length, 9999, "127.0.0.1");
    console.log('Sent OSC message to %s:%d', "127.0.0.1", 9999);
  
  }    
  udp.bind(10000);
  console.log('Listening for OSC messages on port 10000');
  </code></pre>
  
  <p>The problem is, the server's message never seems to reach the client. Once the server receives the message, it produces output as such:</p>
  
  <pre><code>Listening for OSC messages on port 9998
  { address: '/Velocity1',
  args: [ { type: 'integer', value: 100 } ],   oscType: 'message' }
  Sent OSC message to client-public-ip:10000
  </code></pre>
  
  <p>But the client simply hangs on it's initial listening state</p>
  
  <pre><code>Listening for OSC messages on port 10000
  </code></pre>
  
  <p>I thought this may be a problem with my firewall, and I made sure to enable UDP specifically through the port and on all the applications involved, to no gain. I'm hoping to avoid using HTTPRequests. I'd greatly appreciate any suggestions.</p>
  
  <p><a href="https://i.stack.imgur.com/T4Zdc.jpg" rel="nofollow noreferrer">Edit: I created a diagram to help visualize what's supposed to be going on between these three computers. The dashed boxes represent the local network that computer is on (they are all on different networks). I hope this helps a bit.</a></p>