Reputation: 1
I am trying to send and receive requests to the same socket in the following fashion.
Sample of what am trying to do below:
#1
my $sock = IO::Socket::INET->new( Proto=> "tcp", PeerAddr => "$IP",
PeerPort => "$port") ||
die "Could not connect to host => $IP:$port \n";
#2
print $sock $LOGINPDU."\n";
#3
while($ans=<$sock>) {
$ans1.=$ans;
}
$sock->flush();
if($ans1) {
print $sock $transPDU."\n";
#4
while($tns=<$sock>) {
$tns.=$tns;
}
}
#5
$sock->close();
The problem is that I am only receiving response for the first request.
Upvotes: 0
Views: 564
Reputation: 1534
I would guess that the problem is that your script stays in the first while
loop, which waits for the response lines after LOGINPDU
is sent to the server (step 2 -> 3)). This is because readline
(< >
) is blocking and the server did not send an EOF
, which is (with your) code the only option to get out of the loop, but as a side-effect it would also close the connection.
So, if the server's answer is (only) one line you can try something like this:
$ans1=<$sock>;
$sock->flush();
if($ans1) {
...
}
Hope that helped a bit.
Upvotes: 1