1--TEST--
2Streams Based IPv4 TCP Loopback test
3--FILE--
4<?php # vim:ft=php:
5
6  for ($i=0; $i<100; $i++) {
7    $port = rand(10000, 65000);
8    /* Setup socket server */
9    $server = @stream_socket_server("tcp://127.0.0.1:$port");
10    if ($server) {
11      break;
12    }
13  }
14	if (!$server) {
15		die('Unable to create AF_INET socket [server]');
16	}
17
18	/* Connect to it */
19	$client = stream_socket_client("tcp://127.0.0.1:$port");
20	if (!$client) {
21		die('Unable to create AF_INET socket [client]');
22	}
23
24	/* Accept that connection */
25	$socket = stream_socket_accept($server);
26	if (!$socket) {
27		die('Unable to accept connection');
28	}
29
30	fwrite($client, "ABCdef123\n");
31
32	$data = fread($socket, 10);
33	var_dump($data);
34
35	fclose($client);
36	fclose($socket);
37	fclose($server);
38?>
39--EXPECT--
40string(10) "ABCdef123
41"
42