xref: /PHP-5.4/ext/sockets/tests/ipv6loop.phpt (revision 808acd6b)
1--TEST--
2IPv6 Loopback test
3--SKIPIF--
4<?php
5	if (!extension_loaded('sockets')) {
6		die('skip sockets extension not available.');
7	}
8	require 'ipv6_skipif.inc';
9?>
10--FILE--
11<?php
12	/* Setup socket server */
13	$server = socket_create(AF_INET6, SOCK_STREAM, getprotobyname('tcp'));
14	if (!$server) {
15		die('Unable to create AF_INET6 socket [server]');
16	}
17	if (!socket_bind($server, '::1', 31337)) {
18		die('Unable to bind to [::1]:31337');
19	}
20	if (!socket_listen($server, 2)) {
21		die('Unable to listen on socket');
22	}
23
24	/* Connect to it */
25	$client = socket_create(AF_INET6, SOCK_STREAM, getprotobyname('tcp'));
26	if (!$client) {
27		die('Unable to create AF_INET6 socket [client]');
28	}
29	if (!socket_connect($client, '::1', 31337)) {
30		die('Unable to connect to server socket');
31	}
32
33	/* Accept that connection */
34	$socket = socket_accept($server);
35	if (!$socket) {
36		die('Unable to accept connection');
37	}
38
39	socket_write($client, "ABCdef123\n");
40
41	$data = socket_read($socket, 10, PHP_BINARY_READ);
42	var_dump($data);
43
44	socket_close($client);
45	socket_close($socket);
46	socket_close($server);
47?>
48--EXPECT--
49string(10) "ABCdef123
50"
51