YoussefGamil Posted August 29, 2005 Posted August 29, 2005 hi,I have searched the web for PHP ServerSocket..but, all I get is how PHP create the ServerSocket!!!How to create PHP ServerSocket which can read and write? (by exmaples PLZ).Thnx
egrath Posted August 30, 2005 Posted August 30, 2005 Hi,i've never used Socket's in a PHP Script before, but a quick look into the PHP Manual gave me a plenty amount of information about this.Just look in the PHP Manual (downloadable from PHP.net in CHM Format, if you don't have it already) and look for "Socket Functions"Short excerpt:Socket creation:<?php$socket = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr);if (!$socket) { echo "$errstr ($errno)<br />\n";} else { while ($conn = stream_socket_accept($socket)) { fwrite($conn, 'The local time is ' . date('n/j/Y g:i a') . "\n"); fclose($conn); } fclose($socket);}?>How to write to a socket and retrieve data:<?php$fp = stream_socket_client("tcp://www.example.com:80", $errno, $errstr, 30);if (!$fp) { echo "$errstr ($errno)<br />\n";} else { fwrite($fp, "GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n"); while (!feof($fp)) { echo fgets($fp, 1024); } fclose($fp);}?>Hope that helps,Egon
YoussefGamil Posted August 31, 2005 Author Posted August 31, 2005 (edited) Thanks after all..but, It doesn't work!!!! Edited September 7, 2005 by YoussefGamil
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now