Perl socket programming issues after continuous write to socket

I use IO::Socket::INETto create a socket as follows:

$lsn1 = IO::Socket::INET->new(
                            PeerAddr => '192.168.0.2', 
                            PeerPort => 1850, 
                            Proto    => 'tcp', 
                            Type     => SOCK_STREAM
   ) || die "Can't connect to 192.168.0.2:1850 : $!\n"; 

$lsn2 = IO::Socket::INET->new(
                            PeerAddr => '192.168.0.2', 
                            PeerPort = >1852, 
                            Proto    => 'tcp', 
                            Type     => SOCK_STREAM
   ) || die "Can't connect to 192.168.0.2:1852 : $!\n";

then I want to read and write data to both sockets, so the sequence is:

1. $lsn1->print(msg1);  send message 1 to server from $lsn1.
2. $line = <$lsn2>;     receive message 2 from server from $lsn2.
3. $lsn2->print(msg3);  send message 3 to server from $lsn2.
4. $lsn2->print(msg4);  send message 4 to server from $lsn2.
5. $line = <$lsn2>;     receive message 5 from server. But it is all zeros! However I can 
                        see the data on wireshark.

everything will be fine until step 5. After the server side receives my message4 and sends back msg5, which should be captured $line = <$lsn2>, instead of fixing a significant value, it fixes all 0s'. I used wirehark to find out what happened, the RST ACK from my side was sent after the server sent me msg5.

The function on the server received the msg4 message and immediately sent the msg5 message. If I get rid of sending msg4 in this function, then after sending msg5 will be FIN ACK.

- , RST ACK ? perl script , .

+5
1

, 2, (, ..). 5, , , 5.

+3

All Articles