ext-uv/tests/400-tcp_bind.phpt

33 lines
794 B
Plaintext
Raw Normal View History

2012-07-02 06:32:19 +02:00
--TEST--
Check for tcp bind
--FILE--
<?php
$tcp = uv_tcp_init();
uv_tcp_bind($tcp, uv_ip4_addr('0.0.0.0',0));
2015-01-18 02:58:40 +01:00
uv_listen($tcp, 100, function($server){
2012-07-02 06:32:19 +02:00
$client = uv_tcp_init();
uv_accept($server, $client);
2015-01-18 02:58:40 +01:00
uv_read_start($client, function($socket, $nread, $buffer) use ($server) {
2012-07-02 06:32:19 +02:00
echo $buffer . PHP_EOL;
uv_close($socket);
2015-01-18 02:58:40 +01:00
uv_close($server, function() use ($server) {
2012-07-02 06:32:19 +02:00
uv_unref($server);
});
});
});
$addrinfo = uv_tcp_getsockname($tcp);
$c = uv_tcp_init();
2015-01-18 02:58:40 +01:00
uv_tcp_connect($c, uv_ip4_addr($addrinfo['address'],$addrinfo['port']), function($client, $stat) {
2012-07-02 06:32:19 +02:00
if ($stat == 0) {
2015-01-18 02:58:40 +01:00
uv_write($client,"Hello",function($socket, $stat) {
uv_close($socket,function() { });
2012-07-02 06:32:19 +02:00
});
}
});
uv_run();
--EXPECT--
Hello