0
如何將多個客戶端連接到單個服務器,用於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);