title: syscall.Write returns broken pipe while tcp connection establish
body: <h1>Background</h1>
  
  <ul>
  <li>To learn network programming, I tried to write raw socket by Golang, did not use <code>net</code> module.</li>
  </ul>
  
  <h1>Procedure</h1>
  
  <ul>
  <li><ol>
  <li>Server binds socket(<code>syscall.Bind</code>) and listens(<code>syscall.Listen</code>).</li>
  </ol></li>
  <li><ol start="2">
  <li>client tries to connect(<code>syscall.Connect</code>) and server accepts(<code>syscall.Accepts</code>)</li>
  </ol></li>
  <li><ol start="3">
  <li>server responses "Hello" to socket by <code>syscall.Write</code>. </li>
  </ol></li>
  <li><ol start="4">
  <li>client reads socket by <code>syscall.Read</code></li>
  </ol></li>
  </ul>
  
  <p>then, code is here -> </p>
  
  <p><a href="https://gist.github.com/ryfjwr/21e01fb5e133861b41e981e14ced8672" rel="nofollow noreferrer">https://gist.github.com/ryfjwr/21e01fb5e133861b41e981e14ced8672</a></p>
  
  <h1>Problem</h1>
  
  <ul>
  <li><p>above <strong>Procedure</strong>, while executing <strong>step 3</strong>, server exists because of <code>broken pipe</code>.</p></li>
  <li><p>at first, run server</p>
  
  <p>$ go run tcp-server.go</p></li>
  <li><p>then, run client</p>
  
  <p>$ go run tcp-client.go</p></li>
  <li><p>then gets <code>broken pipe</code> error.</p>
  
  <p>$ go run tcp-server.go </p>
  
  <p>Write Error
  broken pipe
  exit</p></li>
  </ul>
  
  <h1>Question</h1>
  
  <ul>
  <li>Why <code>Broken pipe</code> occurs? Any other reserch thing?
  
  <ul>
  <li>I investigated same situation, <code>When you have written to a connection that has already been closed by the peer.</code>, but, I triggerd <code>sleep</code>, before client exits.</li>
  <li>source: <a href="https://stackoverflow.com/questions/34448088/socket-send-function-returned-broken-pipe-error">c++ - Socket: send() function returned 'Broken Pipe' error - Stack Overflow</a> </li>
  </ul></li>
  </ul>