Skip to content

Instantly share code, notes, and snippets.

@jamesBan
Created June 7, 2014 06:03
Show Gist options
  • Select an option

  • Save jamesBan/b91d3a4c94483198b268 to your computer and use it in GitHub Desktop.

Select an option

Save jamesBan/b91d3a4c94483198b268 to your computer and use it in GitHub Desktop.
<?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