Note that there are some explanatory texts on larger screens.

plurals
  1. POC Socket Client not recv()-ing any bytes from server
    primarykey
    data
    text
    <p>Hi I'm building a primitive browser in c which is to do a very simple task. I'm trying to get my client to simply readout the response message from a server that I request from. I'm trying to get a simple response from www.yahoo.com. I have experimented with many different request messages which have all sent successfully. The following request messages are below.</p> <pre><code>GET http://www.yahoo.com HTTP/1.1\r\n Host: www.yahoo.com:80\r\n User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1\r\n Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n Accept-Language: en-us,en;q=0.5\r\n Accept-Encoding: gzip, deflate\r\n Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n Connection: keep-alive\r\n </code></pre> <p>and</p> <pre><code>GET http://www.yahoo.com HTTP/1.1 Host: www.yahoo.com:80 </code></pre> <p>The problem is that I am not recv()-ing any bytes from the server. recv() however does not result in error being -1. Rather the server just doesn't want to respond. Below is my code.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/socket.h&gt; #include &lt;netdb.h&gt; #include &lt;arpa/inet.h&gt; #define MAXDATASIZE 500; int main(int argc, char *argv[]){ struct addrinfo serverSide,*serverInfo; int mySock, status; char buf[501],ipstr[INET6_ADDRSTRLEN]; memset(&amp;serverSide, 0, sizeof serverSide); serverSide.ai_family = AF_UNSPEC; serverSide.ai_socktype = SOCK_STREAM; if(getaddrinfo("www.yahoo.com","80",&amp;serverSide,&amp;serverInfo)==0){ printf("get addr success\n"); } mySock = socket(serverInfo-&gt;ai_family, serverInfo-&gt;ai_socktype, serverInfo-&gt;ai_protocol); connect(mySock, serverInfo-&gt;ai_addr, serverInfo-&gt;ai_addrlen); char msg[500] = "GET / HTTP/1.1\r\n"; strcat(msg," Host: www.yahoo.com:80\r\n"); printf("%s\n",msg); if((status = send(mySock,msg,strlen(msg),0))== -1){ printf("request not sent %d\n",status); perror("\n"); }else{ if((status = recv(mySock, buf, 500, 0))== -1){ printf("recieved byte error"); }else{ printf("%s\n Number of bytes recieved %d\n",buf,status); } } close(mySock); freeaddrinfo(serverInfo); return 0; } </code></pre> <p>Any help would be great. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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