Created
June 7, 2014 06:03
-
-
Save jamesBan/b91d3a4c94483198b268 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $perror = function($msg){ | |
| $errorCode = socket_last_error(); | |
| $errorMsg = socket_strerror($errorCode); | |
| exit("$msg: [$errorCode] $errorMsg\r\n"); | |
| }; | |
| if(!$socket = socket_create(AF_INET, SOCK_STREAM, 0)){ | |
| $perror('could not create scoket'); | |
| } | |
| if(!socket_connect($socket, '168.192.122.78', 8989)){ | |
| $perror('can not connect'); | |
| } | |
| echo "connection established\n"; | |
| $message = "GET / HTTP/1.1\r\n"; | |
| if(!socket_send($socket, $message, strlen($message), 0)){ | |
| $perror("could not send data"); | |
| } | |
| if(socket_recv($socket, $buf, 1024, MSG_WAITALL) === false){ | |
| $perror("Could not receive data"); | |
| } | |
| echo "<hr/>"; | |
| echo $buf; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment