murkata86

PHP

Mar 16th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. $PORT = 20222; //the port on which we are connecting to the "remote" machine
  4. $HOST = "localhost"; //the ip of the remote machine (in this case it's the same machine)
  5.  
  6. $sock = socket_create(AF_INET, SOCK_STREAM, 0) //Creating a TCP socket
  7.         or die("error: could not create socket\n");
  8.  
  9. $succ = socket_connect($sock, $HOST, $PORT) //Connecting to to server using that socket
  10.         or die("error: could not connect to host\n");
  11.  
  12. //$text = "Hello, Java!"; //the text we want to send to the server
  13.  
  14. //socket_write($sock, $text . "\n", strlen($text) + 1) //Writing the text to the socket
  15.         //or die("error: failed to write to socket\n");
  16.  
  17. $reply = socket_read($sock, 10000, PHP_NORMAL_READ) //Reading the reply from socket
  18.         or die("error: failed to read from socket\n");
  19.  
  20. echo $reply;
  21. ?>
Add Comment
Please, Sign In to add comment