This question is two-fold, but if someone could help me with the first question, it would probably solve my problem.
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");
$sk = socket_connect($socket, "192.168.3.136", "3689");
$packet = "GET /login?87893974 HTTP/1.1\r\n";
$packet .= "Connection: close\r\n\r\n";
socket_write($socket, $packet, strlen($packet));
do{
$buf = "";
$buf = socket_read($socket, 4096);
$data .= $buf;
echo "hello";
}while($buf != "");
echo "$data\r\n\r\n";
That code works fine. However, if I change
Connection: close
to
Connection: keep-alive
I cannot read anything back from the socket. I have opened wireshark, to verify that the server is responding to my computer, and it is. PHP is just not reading the response back.
Again, if I have
Connection: close
then all is fine.
The reason
Connection: keep-alive
is important to me is that I need to send this request, read the value that it sends back and post that value back to the server for verification....all on the same "session". With
Connection: close
, I can't seem to write a second time to the same socket.
Which brings me to my second question:
Does specifying Connection: close, tell the server to close the connection? Is that why I can't send data to it on the same socket a second time?