Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sockets

Status
Not open for further replies.

123321a

Programmer
Aug 27, 2003
8
MX
Socket connects successfully a lot of main urls but some are lost I was trying to connect for example Amazon.com but the connection is refused I don{t Know how to configure a client to connect all urls.
Tnanks in advanced.....

 
Was the connection refused, or did it timeout? If it was refused, then your socket did not connect successfully.

Are you writing your own client? Or are you using a web browser and getting timeouts on some of the links?


pansophic
 
I am writing my own client, I configure each step and unsuccessfully step return a message the connection is unseccessfully because the client return an empty content specifically from Amazon using a POST method; the next is the client:

socket(SERVER,AF_INET,SOCK_STREAM,getprotobyname('tcp'));

$iaddr = inet_aton($host) || return(700,"Invalid Host: $host");
$paddr = sockaddr_in(80, $iaddr) || return(700,"Invalid paddr: $host");

socket(SOCK, AF_INET, SOCK_STREAM, $proto) || return (700,"socket error: $!");
connect(SOCK, $paddr) || return (400,"connect error: $!");
select(SOCK);$|=1;
select(STDOUT);

print SOCK "POST $request HTTP/1.0\n",'Host: ',$host,"\n";
print SOCK "Content-Type: application/x- print SOCK "Content-Length: $len\n\n";
print SOCK "$vars\n\n";

while (defined($line = <SOCK>)) {
my $now = time;
$diff = ($now-$start);
if( $diff >= $timeout ) { return(600,&quot;Timeout&quot;); }
$header .= $line;
}
return(500,&quot;Connection refused!&quot;) unless $header;
close (SOCK) || return( 700,&quot;close error: $!&quot; );
 
This is what I get when I do a query on their site. Of course some of this is browser dependant, but they may require some of fields, like Referer, Pragma, Cache-control, Cookie, url, and many of the Accept statements. Otherwise your code looks OK as far as I can tell, but I am far from a programmer, even if it is just PERL.

POST /exec/obidos/search-handle-form/002-3284660-5636834 HTTP/1.1
Connection: Keep-Alive
User-Agent: Mozilla/5.0 (compatible; Konqueror/3.1)
Referer: Pragma: no-cache
Cache-control: no-cache
Accept: text/*, image/jpeg, image/png, image/*, */*
Accept-Encoding: x-gzip, x-deflate, gzip, deflate, identity
Accept-Charset: utf-8, utf-8;q=0.5, *;q=0.5
Accept-Language: en
Host: Cookie: obidos_path_continue-shopping=continue-shopping-url=/subst/home/home.html/002-3284660-5636834&continue-shopping-post-data=&continue-shopping-description=generic.gateway.default; session-id=002-3284660-5636834; session-id-time=1062835200; ubid-main=430-2633098-7782167
Content-Type: application/x-Content-Length: 65

url=index%3Dbooks&field-keywords=computer+search&Go.x=9&Go.y=7

I'd try your queries manually using telnet with differing option sets before I assumed the code was bad.


pansophic
 
Thanks,

Late, but I understood, now the script is working,
thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top