[cs631apue] Best way to read from a socket

lbustama lbustama at stevens.edu
Tue Dec 3 01:15:34 EST 2013


Hi, Just wondering what the best way to read from a socket is?

Do we have to read from the socket character by character until a '/r' 
and '/n' is found?  is there a better way?

while((n = read(fd, &character, 1) != 0)
{
   /* copy char to buffer and check if /n */
   if (character == '\n')
   {
      if (buffer[pos - 1] == '\r')
      {
        break;
      }
   }
}


Thanks,

Luis


More information about the cs631apue mailing list