0

At first am checking the arguments and creating a socket which can connect to a server and defined a file where I can write my HTTP request and when there is a data, I need to Process the line that we have read, through getline and after this I should check end of stream and at the end of stream I need to close the stream and exit.but I do not know how can I check the Endofline...and whther the format written by me are correct

int main(int argc, char *argv[])
{ 
if(argc<2) //checking arguments
{
printf("expected a name for resolving");
exit(1);
}

int sock = createSocket(argv[1], argv[2]);
FILE *stream = getStream(sock);
printf("\n###### CLIENT IS SENDING THE FOLLOWING TO THE SERVER\n");
 fputs("GET /HTTP/1.0\n Host:Google.com\n Connection:close \r\n\r\n",stream);

while(1) 
{
char *string = NULL;
int len = getLine(&string, stream);
int numbytes=0;
printf("The length of string: %d\n",len);
printf("#####CLIENT RECEIVED THE FOLLOWING FROM SERVER \n%s", string);      

while (fgetc(stream) != EOF)
++numbytes;
fclose(stream);
printf("##### Connection closed by server");
exit(EXIT_SUCCESS);
free(string);

} 


}
user2014111
  • 693
  • 1
  • 7
  • 14
  • I don't understand the question, or the code. Why are you just reading one line and then throwing away all other input until EOS? What's the purpose here? – user207421 Feb 13 '13 at 09:38

1 Answers1

-1

I doubt if this is gonna ever work... reading and writing to socket is performed through send and recv commands.

A sample code for http client is kept here:

http://coding.debuntu.org/c-linux-socket-programming-tcp-simple-http-client

Anshul
  • 1,416
  • 1
  • 16
  • 42
  • It can be done via `stdio` as shown, although whether that's a good idea is another question. You haven't really answered the question. – user207421 Feb 13 '13 at 09:37