Send Broadcast datagram

后端 未结 3 1277
故里飘歌
故里飘歌 2020-12-24 03:23

I need to send a broadcast datagram to all machine (servers) connected to my network.

I\'m using NodeJS Multicast

Client

var         


        
3条回答
  •  遥遥无期
    2020-12-24 03:32

    I never used Node.js, but I do recall that with Berkely sockets (which seem to be the most widely used implementation of sockets) you need to enable the SO_BROADCAST socket option to be able to send datagrams to the broadcast address. Looking up the dgram documentation, there seems to be a function for it.

    var client = dgram.createSocket("udp4");
    client.setBroadcast(true);
    client.send(message, 0, message.length, 41234, "192.168.0.255");
    

    You might want to find out the broadcast address programmatically, but I can't help you with that.

提交回复
热议问题