socket

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hareldo
Forum Newbie
Posts: 8
Joined: Sun Jun 22, 2008 7:50 am

socket

Post 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?
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: socket

Post 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?
hareldo
Forum Newbie
Posts: 8
Joined: Sun Jun 22, 2008 7:50 am

Re: socket

Post by hareldo »

some computer going to connect to this socket.
do you have another way to do this?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: socket

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
hareldo
Forum Newbie
Posts: 8
Joined: Sun Jun 22, 2008 7:50 am

Re: socket

Post by hareldo »

how it possible that this script run more then one time?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: socket

Post 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"
There are 10 types of people in this world, those who understand binary and those who don't
hareldo
Forum Newbie
Posts: 8
Joined: Sun Jun 22, 2008 7:50 am

Re: socket

Post by hareldo »

run with apache(on windows).
its show me an error about the socket_bind()
Post Reply