Advertisement
AnotherTest

Client Example v2

Jun 21st, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.55 KB | None | 0 0
  1. <?php
  2. // Indefinite execution
  3. set_time_limit (0);
  4. // IP and port
  5. $strIp = '';
  6. $intPort = 9000;
  7. $strClientIP = getHostByName(gethostname());
  8. // Create a TCP Stream socket
  9. $resSock = socket_create(AF_INET, SOCK_STREAM, 0);
  10. // Connect to the server
  11. socket_connect($resSock, $strIp, $intPort) or die('Could not bind to address');
  12.  
  13. socket_write($resSock, 'CONNECT~' . $strClientIP);
  14. $strMessage = '';
  15. while($strMessage == '') {
  16.     $strMessage = socket_read($resSock, 1024);
  17. }
  18. echo $strMessage;
  19. // Close connection with server
  20. socket_close($resSock);
  21. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement