Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Php
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socket, '127.0.0.1', 1337);

socket_recvfrom($socket, $buffer, 16, 0, $fromAddr, $fromPort);
echo "[{$fromAddr}:{$fromPort}]\t{$buffer}";

// Send a test from the command line such as:
// echo "hello" > /dev/udp/127.0.0.1/1337

PHP can actually do UDP listening and reading. This example is taken straight from the manual.
import std.socket;
ubyte[1024] b;

auto sock = new UdpSocket();
scope(exit) sock.close;

sock.bind(new InternetAddress(p));
sock.receive(b);

New implementation...
< >
programming-idioms.org