Esempio n. 1
0
 /**
  * @param callable $callback
  * @return ServerInterface
  */
 public function recv(callable $callback)
 {
     $this->on(['data'], $callback);
     if ($this->registeredListener !== true) {
         $server = $this;
         \uv_udp_recv_start($this->getBackend(), function ($stream, $nread, $buffer) use($server) {
             $server->emit(new Event('data'), [$server]);
         });
     }
     return $this;
 }
Esempio n. 2
0
<?php

$udp = uv_udp_init();
var_dump($udp);
uv_udp_bind($udp, uv_ip4_addr('0.0.0.0', 10000));
uv_udp_recv_start($udp, function ($stream, $nread, $buffer) {
    echo "recv:" . $buffer;
    uv_close($stream);
});
$uv = uv_udp_init();
uv_udp_send($uv, "Hello", uv_ip4_addr("0.0.0.0", 10000), function ($uv, $s) {
    echo "success" . PHP_EOL;
    uv_close($uv);
});
uv_run();