node.jsmacosudpclient

Node JS: UDP Client does not work in OSX (11.2.2)


I have a windows machine running a udp-server and I try to create a UDP->WebSocket Bridge using node-js... But I just came as far as connection to the server which seems to run nice on windows but fails on osx.

Using this code:

var PORT = 8005;
var HOST = '192.168.1.33';
 
var dgram = require('dgram');
var message = new Buffer.from('CONNECTED');
 
var client = dgram.createSocket('udp4');

client.on('listening', function () {
    var address = client.address();
    console.log('UDP Server listening on ' + address.address + ":" + address.port);
});

client.on('message', function (message, remote) {

    console.log(remote.address + ':' + remote.port +' - ' + message);

});

client.send(message, 0, message.length, PORT, HOST, function(err, bytes) {

    if (err) throw err;
    console.log('UDP message sent to ' + HOST +':'+ PORT);

});

Windows outputs nice:

UDP Server listening on 0.0.0.0:65054
UDP message sent to 192.168.36.1:8005
192.168.36.33:8005 - OK

OSX Just:

UDP Server listening on 0.0.0.0:50360
UDP message sent to 192.168.36.1:8005

The Windows server reports a socket error which normaly means there is a network-issue.

I wonder where the problem is, looks like OSX blocks the udp-connection for some reason but I have no firewall or other filter activated or installed on my mac.

Any idea?


Solution

  • Seems the problem is solved, when I disable Wifi and just use my ethernet connection. Seems to be an issue when two network interface are available. Maybe it sends out on device1 but listens on device2...