-1

我有以下内容:

$host = "192.168.0.117";
$port = 777;

set_time_limit(0);

$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not createsocket\n");
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");

该变量result给了我一个错误:

无法在套接字 [0] 上侦听:提供的参数无效

4

2 回答 2

1
$host = '192.168.0.117';
$port = '777';

set_time_limit(0);

$socket = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($socket, $adddress, $port) or die("Could not connect");
socket_listen($socket);

$client_connection = socket_accept($socket);
$input = socket_read($client_connection, 1024);

$output = ereg_replace('[\t\n\r]','', $input).chr(0);

//display output
socket_write($client_connection, $output);

socket_close($client_connection);
socket_close($socket);
于 2012-10-19T12:47:03.940 回答
1

您需要先将套接字绑定到(地址,端口)对,然后才对其调用监听。

于 2012-10-19T12:40:53.410 回答