Php Socket Client


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $host="localhost" ;
  3. $port=12345;
  4. $timeout=30;
  5. $sk=fsockopen($host,$port,$errnum,$errstr,$timeout) ;
  6. if (!is_resource($sk)) {
  7. exit("connection fail: ".$errnum." ".$errstr) ;
  8. } else {
  9. fputs($sk, "hello world") ;
  10. $dati="" ;
  11. while (!feof($sk)) {
  12. $dati.= fgets ($sk, 1024);
  13. }
  14. }
  15. fclose($sk) ;
  16. echo($dati) ;
  17. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.