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.
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 fdopen
if you are on Unix).