Reputation: 43518
I have the following php script (tcp server)
<?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);
?>
How I can make the server wait the [FIN + ACK] from the client before closing the socket?
Upvotes: 0
Views: 559
Reputation: 3541
You can instead of calling close
, do a recv
on socket (not sure of php construct). recv
system call returns 0 on peer closure. If this is the case you can then close
on server side.
Upvotes: 1