Page 1 of 1

socket

Posted: Sat Jan 03, 2009 3:02 pm
by hareldo
when i run this code:

Code: Select all

<?php 
set_time_limit (0); 
 
$address = '127.0.0.1'; 
$port = 1234; 
 
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, $address, $port) or die('Could not bind to address'); 
 
socket_listen($sock); 
$client = socket_accept($sock);
 
socket_close($sock); 
?>
sometimes its work but sometimes its doesnt work.what can be the problem?

Re: socket

Posted: Sat Jan 03, 2009 6:38 pm
by it2051229
interesting.... what're you trying to achieve? some computer going to connect into your socket? or your computer going to connect to someone's socket?

Re: socket

Posted: Sun Jan 04, 2009 9:39 am
by hareldo
some computer going to connect to this socket.
do you have another way to do this?

Re: socket

Posted: Sun Jan 04, 2009 9:53 am
by VladSun
Maybe you have more than one instance of this PHP script running at a time - after the first one has binded to this port every other attempt to bind to this port will fail.

Re: socket

Posted: Sun Jan 04, 2009 11:00 am
by hareldo
how it possible that this script run more then one time?

Re: socket

Posted: Sun Jan 04, 2009 12:19 pm
by VladSun
How do you run this script? Console? Apache?
sometimes its work but sometimes its doesnt work.
Could you be more specific - it's hard for me to guess what "is not working"

Re: socket

Posted: Sun Jan 04, 2009 1:47 pm
by hareldo
run with apache(on windows).
its show me an error about the socket_bind()