Socket_bind - cannot read from socket. why?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux