summaryrefslogtreecommitdiff
path: root/ext/standard/tests/network/udp4loop.phpt
blob: 92709233ba19c5e2a1804c2ef06255cbc093cb03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--TEST--
Streams Based IPv4 UDP Loopback test
--FILE--
<?php
    /* Setup socket server */
    for ($port = 31338; $port < 31500; ++$port) {
      $uri = "udp://127.0.0.1:$port";
      $server = @stream_socket_server($uri, $errno, $errstr, STREAM_SERVER_BIND);
      if ($server) break;
    }
    if (!$server) {
        die('Unable to create AF_INET socket [server]: ' . $errstr);
    }

    /* Connect to it */
    $client = stream_socket_client($uri);
    if (!$client) {
        die('Unable to create AF_INET socket [client]');
    }

    fwrite($client, "ABCdef123\n");

    $data = fread($server, 10);
    var_dump($data);

    fclose($client);
    fclose($server);
?>
--EXPECT--
string(10) "ABCdef123
"