httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djwiktor <wsoko...@poczta.onet.pl>
Subject [users@httpd] Socket_bind - cannot read from socket. why?
Date Sun, 14 Sep 2008 18:13:30 GMT

I have a problem with a simple (allegedly) function to read socket data and
save it in a file.
The code look as follows:

// 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

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

-- 
View this message in context: http://www.nabble.com/Socket_bind---cannot-read-from-socket.-why--tp19482798p19482798.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message