Note that there are some explanatory texts on larger screens.

plurals
  1. POReceiving data from remote server
    text
    copied!<p>I am having problems receiving data from a remote server. It seems that I can send an HTTP request to a host such as <a href="http://www.google.com" rel="nofollow">http://www.google.com</a>, but I can't get a reply. I'm sending the host a HTTP 1.0 request that is formatted as such:</p> <p>GET / HTTP/1.0<br> Host: www.google.com<br> Connection: close</p> <p>Here are is part of the proxy code:</p> <pre><code> //Parse Request Buffer HttpRequest req; req.ParseRequest(request.c_str(), request.length()); //Format Data to be Sent: req.AddHeader ("Connection", "close"); // add connection close headers req.SetVersion ("1.0"); // set http 1.0 flag char *requestBuf = new char [req.GetTotalLength()]; req.FormatRequest(requestBuf); //Get host IP by name struct hostent *host; host = gethostbyname(req.GetHost().c_str()); //Setup remote address structure struct sockaddr_in remoteAddr; remoteAddr.sin_family = AF_INET; remoteAddr.sin_port = htons(req.GetPort()); remoteAddr.sin_addr = *((struct in_addr *)host-&gt;h_addr); //create new socket for remote server int remoteSock = socket(AF_INET, SOCK_STREAM, 0); if(remoteSock &lt; 0) { perror("Socket Error"); //return -1; } //connecting to remote server if(connect(remoteSock, (struct sockaddr *)&amp;remoteAddr, sizeof(remoteAddr)) &lt; 0) { perror("Connect Error"); //return -1; } cout.flush() &lt;&lt; requestBuf &lt;&lt; endl; //send request to remote server if(send(remoteSock, requestBuf, sizeof(requestBuf), 0) &lt; 0) { perror("Write Error"); //return -1; } //receive reply from server char *recBuf = new char [1024]; int bufSize = 1024; int readSize; while(1) { readSize = read(remoteSock, recBuf, bufSize); //Read from Remote Server cout.flush() &lt;&lt; recBuf &lt;&lt; endl; if(readSize &lt;= 0) //If the requestBuf not filled, nothing left to send to client break; write(clientSock, recBuf, readSize); //write reply to Client } close(remoteSock); </code></pre> <p><br> The cout.flush() of recBuf outputs nothing.<br> Any ideas on whats going on?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload