August 29, 200521 yr 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
August 30, 200521 yr 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
August 31, 200521 yr Author Thanks after all..but, It doesn't work!!!! Edited September 7, 200520 yr by YoussefGamil
Create an account or sign in to comment