Adamba has asked for the wisdom of the Perl Monks concerning the following question:
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 = ( "example.com", "google.com", ); 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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Asynchronous HTTP Request using specific ports
by zwon (Abbot) on Apr 04, 2013 at 11:37 UTC | |
by Adamba (Sexton) on Apr 04, 2013 at 12:09 UTC | |
by zwon (Abbot) on Apr 04, 2013 at 14:08 UTC | |
by Adamba (Sexton) on Apr 04, 2013 at 15:10 UTC | |
by zwon (Abbot) on Apr 04, 2013 at 16:17 UTC | |
| |
Re: Asynchronous HTTP Request using specific ports
by andal (Hermit) on Apr 05, 2013 at 07:42 UTC | |
Re: Asynchronous HTTP Request using specific ports
by Anonymous Monk on Apr 04, 2013 at 11:16 UTC | |
by Adamba (Sexton) on Apr 04, 2013 at 12:08 UTC |