Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm trying to write a script that will HTTP get some urls but with specific source ports.

The idea of using a specific port is to mark with dscp my packets

I've tried to use WWW::Curl::Multi and AnyEvent::HTTP, but i'm always ending with the same problem, the socket is hanging with TIME_WAIT, and I can't reuse the source port that the socket is stuck with, i'm getting this error msg: bind failed with errno 98: Address already in use
I've tried each of the fixes from google, like changing tcp_tw_recycle and tcp_tw_reuse, but it still not working...

The last option that i'm trying is using IO::Socket::INET with Blocking 0, but I'm having trouble with my code:

#!/usr/bin/perl use strict; use warnings; use IO::Socket; use IO::Select; my @ports = qw/65051 65071 65052 65072 65081 65088 65082 65039/; my @hosts = ( "", "", ); my $readers = IO::Select->new(); foreach my $host (@hosts) { foreach my $port (@ports) { print "* Trying: $host\n"; my $socket = IO::Socket::INET->new( PeerAddr => $host, PeerPort => "http(80)", LocalPort => $port, Proto => 'tcp', ReuseAddr => 1, Blocking => 0, ) or die "Couldn't connect to server: $!"; $readers->add($socket); print $socket "GET / HTTP/1.0\r\n\r\n"; $socket = undef; } print "\n"; } while (1) { foreach my $sock (my @ready_for_read = $readers->can_read()) { my @recv_lines = <$sock>; print join "\n", map { s/\r?\n//; $_ } @recv_lines; print "\n"; $readers->remove($sock); $sock->close; } }

Where have I got wrong?

Thanks in advance, Adam

In reply to Asynchronous HTTP Request using specific ports by Adamba

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (5)
    As of 2018-05-25 21:45 GMT
    Find Nodes?
      Voting Booth?