因此,我已经用这段代码测试了套接字,它正在运行精细 (SOCK_STREAM)。
<?php
set_time_limit(0);
$sock = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket \n");
$result = socket_bind($sock, $host, $port) or die("Could not bind to socket \n");
$result = socket_listen($sock, 3) or die("Dould not set up socket listener \n");
echo "Listening for connection \n";
// LOOP FOREVER
do {
$accept = socket_accept($sock) or die ("Could not accept incoming connection \n");
$msg = socket_read($accept, 100000) or die("Could not read input \n");
echo "Client says: " . $msg . "\n\n\n";
} while(true);
socket_close($accept, $sock);但问题是当我试图将socket_create()更改为SOCK_RAW时
$sock = socket_create(AF_INET, SOCK_RAW, 1) or die("Could not create socket \n");或
$sock = socket_create(AF_INET, SOCK_RAW, 0) or die("Could not create socket \n");或
$sock = socket_create(AF_INET, SOCK_RAW, getprotobyname('icmp')) or die("Could not create socket \n");我有以下错误:
PHP Warning: socket_listen(): unable to listen on socket [10045]: The attempted operation is not supported for the type of object referenced in C:\xampp\htdocs\wialon php script\server.php on line 10
Warning: socket_listen(): unable to listen on socket [10045]: The attempted operation is not supported for the type of object referenced in C:\xampp\htdocs\wialon php script\server.php on line 10
Dould not set up socket listener请帮帮忙。提前谢谢你。
发布于 2022-09-21 18:39:52
不能对原始套接字使用socket_listen() (扩展为socket_accept())。它们只对面向连接(即: TCP等)套接字有意义。PHP文档甚至这样说:
https://www.php.net/manual/en/function.socket-listen.php
socket_listen()只适用于SOCK_STREAM或SOCK_SEQPACKET类型的套接字。
https://www.php.net/manual/en/function.socket-accept.php
在使用socket_listen(),创建套接字socket之后,将其绑定到带有socket_bind()、并被告知侦听与 socket_create()的连接的名称之后,该函数将在该套接字上接受传入的连接。
https://stackoverflow.com/questions/73797817
复制相似问题