2

I have the following perl script to send pipelined http request over a sinlge tcp connection. The first request goes through and i am able to get the response. The second reqeust also gets sent, but no response is received for this request. I am able to see both requests being received on the server in the trace.

use IO::Socket::INET;
$| = 1;

$socket = new IO::Socket::INET (
   PeerHost => '10.102.218.56',
   PeerPort => '80',
   Proto => 'tcp',);
die "cannot connect to the server $!\n" unless $socket;
print "connected to the server\n";

# data to send to a server
my $req = "GET /test/file5.html HTTP/1.1\r\nHost:10.102.218.50\r\nAccept: */*\r\n\r\n\r\n";
my $size = $socket->send($req);
print "1. sent data of length $size\n";

$socket->recv($response, 1024);
print "received response: $response\n";

my $req = "GET /test/file5.html HTTP/1.1\r\nHost:10.102.218.50\r\nAccept: */*\r\n\r\n\r\n";
my $size = $socket->send($req);
print "1. sent data of length $size\n";

$socket->recv($response, 1024);
print "received response: $response\n";
sleep 1;
$socket->close();

On the Apache access_log i see only one instance of the HTTP request being received :

10.102.218.50 - - [02/Sep/2014:23:04:50 +0530] "GET /test/file5.html HTTP/1.1" 200 6 "-" "-"

I am guessing that I am missing some characters that indicate the end of an HTTP request of the server. But i am not able to find what they are.

What am i doing wrong here?

Edit: Could the Apache server be closing the connection after the first HTTP request is answered. Is there a setting for this?

Edit2: KeepAlive was set to Off on my apache server. Setting it to ON fixes the issue.

Rishabh
  • 199
  • 3
  • 14

1 Answers1

0

Found the problem. The KeepAlive was set to off on my Apache server. Setting the KeepAlive to On fixed the problem.

Rishabh
  • 199
  • 3
  • 14