如何将多个客户端连接到单个服务器,用于 2 个客户端之间的简单聊天应用程序。我在网上没有得到正确的答案,我是否必须创建多个套接字或端口,任何参考或示例代码或指导......这是我的服务器代码
$host = "127.0.0.1";
$port = 25003;
// No Timeout
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
//echo $socket;
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
$input = socket_read($spawn, 1024) or die("Could not read input\n");
$output = strrev($input);
socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
socket_close($spawn);
socket_close($socket);