如何发udp广播到192.168.1.255上?

beginning

workerman怎么样去发广播?
比如发送udp广播到192.168.1.255上

5374 1 1
1个回答

walkor 打赏

udp广播直接用php的接口就行

php手册的例子:
http://php.net/manual/en/function.socket-sendto.php#57746

workerman中的例子:
https://github.com/walkor/workerman-statistics/blob/master/Applications/Statistics/Modules/admin.php#L25

$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);
socket_sendto($sock, $broadcast_string, strlen($broadcast_string), 0, '255.255.255.255', $port);

  • 暂无评论
年代过于久远,无法发表回答
×
🔝