title: UNIX TCP/IP :read: Transport endpoint is not connected read: Transport endpoint is not connected
body: <p>I'm trying to use the following program to show the message recived form port <code>8888</code>.
  I compiled the following code without any error and warning.</p>
  <p>After I run it, I use a broswer to open <code>127.0.0.1:8888</code></p>
  <p>Then, the console showed:</p>
  <pre><code>read: Transport endpoint is not connected
  read: Transport endpoint is not connected
  </code></pre>
  <p>I debug it, but I can't find the reason.</p>
  <h3>platform</h3>
  <p>Linux kernel 3.x Ubuntu 64bit</p>
  <h3>code</h3>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;netinet/in.h&gt;
  //#include &lt;errno.h&gt;
  
  int main(int argc, char *argv[])
  {
      int sock;
      char buf[BUFSIZ+1];
  
      buf[BUFSIZ] = '\0';
      uint16_t port = (uint16_t)atoi(&quot;8888&quot;);
      struct sockaddr_in ser;
      memset(&amp;ser, 0, sizeof(ser));
      ser.sin_port = htons(port);
      ser.sin_addr.s_addr = htonl(INADDR_ANY);
      ser.sin_family = AF_INET;
  
      sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
      if(sock &lt; 0)
      {
          perror(&quot;socket&quot;);
          return -7;
      }
  
      /*Bind*/
      if (bind(sock, (struct sockaddr *)&amp;ser, sizeof(ser)) &lt; 0)
          return -2;
  
      /*listen*/
      if (listen(sock, 5) &lt; 0)
          return -3;
  
      /*Accpet*/
      struct sockaddr_in cliAddr;
      socklen_t cliLen = sizeof(cliAddr);
      if (accept(sock, (struct sockaddr*)&amp;cliAddr, &amp;cliLen) &lt; 0)
      {
          perror(&quot;accept&quot;);
          exit(1);
      }
      int read_len = 0;
      int i = 0;
  
      /*read and print*/
      while(1)
      {
          read_len = read(sock, buf, BUFSIZ);
          if(read_len &lt; 0)
          {
              perror(&quot;read&quot;);
              break;
          }
          else
          {
              /*print buf*/
              while(i++ &lt; read_len)
                  putchar(buf[i-1]);
              putchar('\n');
          }
          if(read_len != BUFSIZ)
              break;
      }
      return 0;
  }
  </code></pre>
  <p>If you found any bad habits in my code, please tell me.</p>