I could reduce the time to 2 seconds using Net::Pcap here is the code , I am positive that there is a easier way , but this code works for me, I hope it helps!.
use IO::Socket; use Net::Pcap; use NetPacket::Ethernet qw(:strip); use NetPacket::TCP; use NetPacket::IP qw(:strip); use List::Util qw(first); # Find all interfaces. my @interfaces = Net::Pcap::findalldevs(\%devinfo, \$err); my $int = first { $devinfo{$_} =~ /Real/ } @interfaces; #print $int; in my case i want to find Realtech interface $snaplen = 1515; #Package lenght $promisc = 1; #Captur packages in promiscious mode $timeout = 30; $count = 12; # (count = 0 = forever) here is the number of packages yo +u want to capture my $pcap = Net::Pcap::open_live( $int,$snaplen,$promisc,$timeout,\$err ); #Select the interface you want to capture packages , and it's informat +ion my $socket = new IO::Socket::INET ( PeerAddr => '192.168.11.244', PeerPort => '6008', Proto => 'tcp', ); die "Couldn't connect: $!\n" unless $socket; $data = pack("CccccccCcCC",02,65,63,80,81,76,86,03,100,13,10); if ( $socket ) { print $socket $data ; Net::Pcap::loop($pcap, $count, \&callback, $user_data); sleep 1; # the device takes 1 second to answer } close($socket); sub callback { my ($user_data, $header_ref, $packet) = @_; $ip = NetPacket::IP->decode(eth_strip($packet)); $tcp = NetPacket::TCP->decode($ip->{data}); if ( $tcp->{src_port} == 6008 ) { $payload = $tcp->{data}; print "$ip->{src_ip}:$tcp->{src_port} --> $ip->{dest_ip}:$tcp->{dest_p +ort} Payload: $payload\n"; } }

In reply to Re^13: IO::Socket Listen by Secalles
in thread IO::Socket Listen by Secalles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.