Advertisement
Tustin

socket file sender

Jul 24th, 2017
1,451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2. const SERVER_IP = "0.0.0.0"; //change to your server's IP or else it will fail to bind the socket
  3. const FILE_NAME = "Tesseract.sprx"; //change to the relative file location for the file you want to transfer
  4. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  5. socket_bind($socket, SERVER_IP, 6969);
  6.  
  7. socket_listen($socket);
  8.  
  9. while (true) {
  10.     $client = socket_accept($socket);
  11.  
  12.     $file = file_get_contents(FILE_NAME);
  13.     socket_write($client, $file);
  14.     //echo "successfully sent " . filesize(FILE_NAME) . " bytes to client\n";
  15.  
  16.     socket_close($client);
  17. }
  18. socket_close($socket);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement