Skip to content

Instantly share code, notes, and snippets.

@smaddock smaddock/udp.php
Created Apr 13, 2016

Embed
What would you like to do?
send basic UDP messages from PHP
<?php
$serverIP = '192.168.0.1';
$serverPort = 5000;
if ($_REQUEST['cmd']) {
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if (!$socket) {
error_log("Could not open socket");
} else {
socket_sendto($socket, $_REQUEST['cmd'], strlen($_REQUEST['cmd']), 0, $serverIP, $serverPort);
socket_close($socket);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.