#! /usr/bin/env rdmd
import std.socket : UdpSocket, InternetAddress, Address;
import std.stdio : writefln;
import std.algorithm : reverse;

void main() {
    scope server = new UdpSocket;
    server.bind(new InternetAddress("localhost", 4444));
    ubyte[128] buffer;
    Address client;
    ptrdiff_t len;

    while (true) {
        len = server.receiveFrom(buffer[], client);
        if (len <= 0)
            continue;
        writefln!"%s said: %s"(client, cast(char[]) buffer[0 .. len]);
        server.sendTo(buffer[0 .. len].reverse, client);
    }
}
