【发布时间】:2015-06-23 05:25:10
【问题描述】:
我有以下 php 脚本(tcp 服务器)
<?php
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
// Bind the socket to an address/port
socket_bind($sock, "0.0.0.0", 14010) or die('Could not bind to address');
$i=0;
for(;;) {
// Start listening for connections
socket_listen($sock);
/* Accept incoming requests and handle them as child processes */
$client = socket_accept($sock);
// Read the input from the client – 1024 bytes
$in = socket_read($client, 41984);
socket_write($client, $in);
//socket_close($client);
}
// Close the master sockets
socket_close($sock);
?>
如何让服务器在关闭套接字之前等待来自客户端的 [FIN + ACK]?
【问题讨论】:
-
您只想
listen一次(在循环外)然后accept多次。
标签: php sockets networking tcp