Search code examples
csocketsrecv

How can i read html page line by line using recv?


I tried to practice socket programming using C language.
What I was trying do is to read certain html page line by line which means read until '\n'.
The problem is, though, because of recv's attribute of reading certain amount of length which we pass as a argument to third argument of recv().
For example,

char buff[256];
.
.
recv(socknumber, buf, sizeof(buff), 0);

In this case, recv read string as much as sizeof(buff). So I had no idea how to deal with '\n'

Since I'm a C virgin, please give me some tip, or simple code. Thanks.


Solution

  • You have to implement it by yourself because there is no concept of line in socket transmissions. There is a lot of solution even in SO, see that one read line by line from a socket buffer. You can also get a FILE handle from your socket descriptor and use *gets functions (have a look at fdopenif you are on Unix).