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
In reply to Asynchronous HTTP Request using specific ports by Adamba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |