SOCKETS IN PHP
Moderator: General Moderators
-
kushaljutta
- Forum Commoner
- Posts: 50
- Joined: Fri Dec 26, 2008 11:05 am
SOCKETS IN PHP
Can anybody help me in creating sockets in php
1.How to create a socket
2.How to send & receive responce from client to server..
thanks in advance
1.How to create a socket
2.How to send & receive responce from client to server..
thanks in advance
Re: SOCKETS IN PHP
what have you tried ?
-
kushaljutta
- Forum Commoner
- Posts: 50
- Joined: Fri Dec 26, 2008 11:05 am
Re: SOCKETS IN PHP
in my project i have done module in that
ie..
writing data into xml file with these sockets only
actually this is gaming project
1...player sends the data to player2 then in this case player2 recieves that data whenever player1 sends that..
in this case i used xml's for this player 2 continuously check whether player1 sends the data or not...
but it is the worst case
so to resolve this problem i want to use sockets..
please help me....
actually my requirement is
==================
create a socket afer that it receives the xml data and writes that xml data in a socket.
please boss
ie..
writing data into xml file with these sockets only
actually this is gaming project
1...player sends the data to player2 then in this case player2 recieves that data whenever player1 sends that..
in this case i used xml's for this player 2 continuously check whether player1 sends the data or not...
but it is the worst case
so to resolve this problem i want to use sockets..
please help me....
actually my requirement is
==================
create a socket afer that it receives the xml data and writes that xml data in a socket.
please boss
Re: SOCKETS IN PHP
my recomendation is to use ajax, as it has on ready events and read/writes into xml directly. this saves yo a lot fo headache of using lower level sockets to do what can easily be done using ajax. if there is some very good reason you wish to use socket, then by all means do so, but most of what is required can be achieved with ajax.
-
kushaljutta
- Forum Commoner
- Posts: 50
- Joined: Fri Dec 26, 2008 11:05 am
Re: SOCKETS IN PHP
thanQ for sending reply
but i need it sockets only
please boss please
help me in how to write data in socket
but i need it sockets only
please boss please
help me in how to write data in socket
-
kushaljutta
- Forum Commoner
- Posts: 50
- Joined: Fri Dec 26, 2008 11:05 am
Re: SOCKETS IN PHP
i got some code in sockets
<?php
$address="74.54.206.242";
$port=80;
$socket=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
echo "socket created".$socket;
$res=socket_connect($socket,$address,$port);
echo "<br/>Result".$res;
socket_write($socket,"get /index.php http/1.0\n\n");
$result="";
while($read=socket_read($socket,1024)){
$result.=$read;
}
echo "<br/>Result received:'$result'\n";
socket_close($socket);
?>
like this code i want to write data into sockets...
the outpt of this code is
===========================
socket createdResource id #1
Result1
Result received:'HTTP/1.1 404 Not Found Date: Wed, 01 Apr 2009 13:05:15 GMT Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Content-Length: 521 Connection: close Content-Type: text/html; charset=iso-8859-1
Not Found
The requested URL /index.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at f6.e2.354a.static.theplanet.com Port 80
'
<?php
$address="74.54.206.242";
$port=80;
$socket=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
echo "socket created".$socket;
$res=socket_connect($socket,$address,$port);
echo "<br/>Result".$res;
socket_write($socket,"get /index.php http/1.0\n\n");
$result="";
while($read=socket_read($socket,1024)){
$result.=$read;
}
echo "<br/>Result received:'$result'\n";
socket_close($socket);
?>
like this code i want to write data into sockets...
the outpt of this code is
===========================
socket createdResource id #1
Result1
Result received:'HTTP/1.1 404 Not Found Date: Wed, 01 Apr 2009 13:05:15 GMT Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Content-Length: 521 Connection: close Content-Type: text/html; charset=iso-8859-1
Not Found
The requested URL /index.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at f6.e2.354a.static.theplanet.com Port 80
'
-
kushaljutta
- Forum Commoner
- Posts: 50
- Joined: Fri Dec 26, 2008 11:05 am
Re: SOCKETS IN PHP
hi PHP_ease ru there...
Re: SOCKETS IN PHP
well, you already have the codes, and so i don't understand what you wanted. if it's in learning on how to use sockets, then i would suggest you play with the codes you already have. and enjoy it while you're at it !. you will learn plenty that way undoubtedly. 
-
kushaljutta
- Forum Commoner
- Posts: 50
- Joined: Fri Dec 26, 2008 11:05 am
Re: SOCKETS IN PHP
hi
thanks for the reply
didnt you understand that code which i already sent..
just tell me one thing that
how to create a socket
2.how to bind that socket
3.how to write the data in to the socket
4.how to read the data in the socket which are written by us
if you send me those details ill really thankful to you...
thanks for the reply
didnt you understand that code which i already sent..
just tell me one thing that
how to create a socket
2.how to bind that socket
3.how to write the data in to the socket
4.how to read the data in the socket which are written by us
if you send me those details ill really thankful to you...
Re: SOCKETS IN PHP
the answers are ALL in the codes you posted.kushaljutta wrote: how to create a socket
2.how to bind that socket
3.how to write the data in to the socket
4.how to read the data in the socket which are written by us
if you send me those details ill really thankful to you...
it is all there, so you can study them, look at each and everyone using the PHP manual, and you will find all the answers there. there is of course a lot lookup to do, but that is how everyone learns.
if you are stuck on specifics, i can answer them.
-
kushaljutta
- Forum Commoner
- Posts: 50
- Joined: Fri Dec 26, 2008 11:05 am
Re: SOCKETS IN PHP
thanks for the reply
i already tried all those things but they gave me fatal errors like
cannot call unefined function....
pipe was broken
and finally
maximum time limit exceeded..
my request is if you have a worked examples please give that example for me
i searched in the google but all those things are not running well....
my need is to run these sockets in browsers..but i saw maximum examples are worked in shell script..
please ...
i already tried all those things but they gave me fatal errors like
cannot call unefined function....
pipe was broken
and finally
maximum time limit exceeded..
my request is if you have a worked examples please give that example for me
i searched in the google but all those things are not running well....
my need is to run these sockets in browsers..but i saw maximum examples are worked in shell script..
please ...
Re: SOCKETS IN PHP
that is very strange indeed becasue i have tried your codes and they work, very well.
i even tried googles site with it and it works too.
so it is likely your problem is your setup, not the codes. before anything else, ensure you have a stable & reliable setup. otherwise, you surely won't get far.
i even tried googles site with it and it works too.
so it is likely your problem is your setup, not the codes. before anything else, ensure you have a stable & reliable setup. otherwise, you surely won't get far.
-
kushaljutta
- Forum Commoner
- Posts: 50
- Joined: Fri Dec 26, 2008 11:05 am
Re: SOCKETS IN PHP
can you send me those worked examples..
cant i change my configuration setup in php.ini
cant i change my configuration setup in php.ini