I have a problem with a simple (allegedly) function to read socket data and save it in a file. The code look as follows:
However, right away after the script is launched I get an error message
This problem occurrs regardless of port number and if it is declared in httpd.conf or not. No matter which server port I use it always seems 'busy'.
Please give me a hint what is the cause of the problem.
Wiktor
Code:
// Set the ip and port we will listen on
$host = '127.0.0.1';
$port = 20000;
set_time_limit(0);
// create low level socket
if(!$socket=socket_create(AF_INET,SOCK_STREAM,0)){
trigger_error('Error creating new socket',E_USER_ERROR);
}
# reuse socket tweak
if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
echo socket_strerror(socket_last_error($socket));
exit;
}
// tie up socket to TCP port
if(!socket_bind($socket,$host,$port)){
trigger_error('Error binding socket to TCP host:'.$host.', port:'.$port.'',E_USER_ERROR);
}
// begin listening connections
if(!socket_listen($socket)){
trigger_error('Error listening socket connections',E_USER_ERROR);
}
// create communication socket
if(!$comSocket=socket_accept($socket)){
trigger_error('Error creating communication socket',E_USER_ERROR);
}
// read socket input
$socketInput=socket_read($comSocket,1024);
//write data to file
....
// close sockets
socket_close($comSocket);
socket_close($socket);
However, right away after the script is launched I get an error message
Code:
PHP Warning: set_time_limit(): Cannot set time limit
PHP Warning: socket_bind() unable to bind address [98]: Address already in use Could not bind to address
This problem occurrs regardless of port number and if it is declared in httpd.conf or not. No matter which server port I use it always seems 'busy'.
Please give me a hint what is the cause of the problem.
Wiktor