这是php代码
<?php
$hostname = "127.0.0.1";
$portno = "5060";
$sock = socket_create(AF_INET, SOCK_STREAM, 0) or die("Socket create error\n");
socket_bind($sock, $hostname, $portno) or die("Socket bind error\n");
socket_listen($sock, 3) or die("Could not set up socket listener\n");
while(1)
{
echo "socket connection started\n";
$accept = socket_accept($sock) or die("Could not accept incoming connection\n");
while($recv = socket_read($accept, 24000))
{
$sent = socket_write($sock, $recv, strlen($recv));
echo $recv;
}
socket_close($accept);
echo "socket connection done\n";
}
socket_close($sock);
?>
它作为 TCP 服务器工作。为了将其转换为 udp 服务器,我在创建服务器时修改了一行
$sock = socket_create(AF_INET, SOCK_DGRAM, 0) or die("Socket create error\n");
但它显示错误
Could not set up socket listener
在尝试听的时候。