Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
ServerAddr,err := net.ResolveUDPAddr("udp",p)
if err != nil {
return err
}
ServerConn, err := net.ListenUDP("udp", ServerAddr)
if err != nil {
return err
}
defer ServerConn.Close()
n,addr,err := ServerConn.ReadFromUDP(b[:1024])
if err != nil {
return err
}
if n<1024 {
return fmt.Errorf("Only %d bytes could be read.", n)
}
$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