p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

vs_dotnet thread: why send error?


Message #1 by Edward <zhangsc@n...> on Fri, 10 May 2002 08:37:08 +0800
I have a puzzled question about socket,send function works well when
when buffer's content is to request text/html type,for example:

buffer="GET  / HTTP/1.0
        Accept: */*
        Referer: http://www.google.com/
        Accept-Language: zh-cn
        Proxy-Connection: Keep-Alive
        User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)
        Host: www.google.com\n";

but when buffer's content is to request .gif type,send function failed,it is
error:"Error while proxy sending server response."  for example:

buffer="GET  /images/hp0.gif HTTP/1.0
        Accept: */*
        Referer: http://www.google.com/
        Accept-Language: zh-cn
        Proxy-Connection: Keep-Alive
        User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)
        Host: www.google.com\n";

 SOCKET server;
 server=socket(AF_INET,SOCK_STREAM,0);
 if(server==SOCKET_ERROR)
 {
       perror("Create socket error");
       return -1;
 }

 struct sockaddr_in local;
 local.sin_family=AF_INET;
 local.sin_port=htons(80);
 struct hostent *hp;
 hp=gethostbyname("www.google.com");
 memcpy(&(local.sin_addr),hp->h_addr,hp->h_length);
 if(connect(server,(struct sockaddr *)&local,sizeof(local))==SOCKET_ERROR)
 {
      perror("Connect error");
      return -1;
 }

 /*send request page*/
 if(send(server,buffer,strlen(buffer),0)==SOCKET_ERROR)
 {
  perror("Error while proxy sending request to server");
  return -1;
 }

/*proxy is a socket I made by accept from IE in my program*/

if(send(proxy,buffer,strlen(buffer),0)==SOCKET_ERROR)
 {
   perror("Error while proxy sending server response");
 ...
 }

/*I think socket proxy is open and not closed,because I try to run this
program twice,first time I get / ,it works well and I can display it in
IE,second time I get /images/hp0.gif, it raise error,like follows:"Error
while proxy sending server response",and I can't display it in IE,in IE,it
only show a box with cross sign,it's error show*/

Why I send .gif type,it will fail and I send other type,it works well???  I
am more puzzled with it. Any ideas will be appreciated!
Thanks in advance!!!
Regard,
Edward






  Return to Index