Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^12: IO::Socket Listen

by Secalles (Initiate)
on Dec 09, 2011 at 12:54 UTC ( #942647=note: print w/ replies, xml ) Need Help??


in reply to Re^11: IO::Socket Listen
in thread IO::Socket Listen

Eliya and Marshall , thanks for helping.

I used wireshark to see the response time of google and it took 3ms to answer me , when i execute my script it returns me the value right away (just like google) but it keeps alive the connection even if the information has been received , I have no idea what is happening ...

I read some stuff about Net::Pcaps , i can try to capture the package but i don't know if it'll work ... Any sugestion ?

Thanks a lot


Comment on Re^12: IO::Socket Listen
Re^13: IO::Socket Listen
by Secalles (Initiate) on Dec 09, 2011 at 14:22 UTC
    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"; } }
      Thanks for sharing your solution with us. It does appear to be a rather 'roundabout way.

      I would have hoped that your experiment results would have shown us where the timing problem was:

      -t0: send ping to google, wireshark timing
      -t1: receive ping from google, wireshark timing
      -t2: send packet to device, wireshark timing
      -t3: receive packet from device, wireshark timing
      -t4: Perl code does something (probably send out a ping so that
      we get a time stamp with wireshark).

      t2-t1 is the time for Perl to send the packet
      t3-t2 is the time for the device to respond
      t4-t3 is the time for Perl to do something

      However, I am glad that you got a solution!
      Perl is like the "Swiss army knife of the internet".

        Thanks Marshall , I'll still try to find what the problem is , if i come across another solution I'll share ,I got some interesting results using the program that the controller developer send me , all the information that you and Eliya shared with me are sure helping! Thanks a lot!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://942647]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-08-30 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls