Advertisement
AnotherTest

Server Example

Jun 21st, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1. <?php
  2. // Indefinite execution
  3. set_time_limit (0);
  4. // IP and port
  5. $strIp = '';
  6. $intPort = 9000; // 9000 is a good port
  7.  
  8. // Create a TCP Stream socket
  9. $resSock = socket_create(AF_INET, SOCK_STREAM, 0);
  10. // Bind the socket to an address/port
  11. socket_bind($resSock, $strIp, $intPort) or die('Could not bind to address');
  12. // Start listening for connections
  13. socket_listen($resSock);
  14. while(true) {
  15.     // Accept incoming requests
  16.     $resClient = socket_accept($resSock);
  17.     // Read input from client
  18.     $strMessage = socket_read($resClient, 1024);
  19.    
  20.     // Display output
  21.     echo $strMessage;
  22. }
  23. // Close the client (child) socket
  24. socket_close($resClient);
  25.  
  26. // Close the master sockets
  27. socket_close($resSock);
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement