title: Can golang net.Conn get notified when there is a new message?
body: <h2><strong>What I try to implement</strong></h2>
  
  <p>I'm implementing a client sending and receiving unixpackets and interacting with a server which was already implemented in C++.<br>
  So far, the client can receive and send packet to server successfully. But I used a for loop to keep calling <strong>Recv</strong> to see if there is a new message.</p>
  
  <h2><strong>What I did</strong></h2>
  
  <p>I implemented a Packet class so that the client and server can follow the same rules to encode and decode the message. Transport is a struct wrapping a <code>net.Conn</code>. Client is consisted of Transport, receiving Packet and sending Packet.<br>
  I used a <strong>for loop</strong> to keep calling <strong>Recv</strong> to see if there's a new message arriving at <code>net.Conn</code>.</p>
  
  <pre><code>type Packet struct {
      Length      uint32
      Data        []byte
      ReadOffset  uint32
      WriteOffset uint32
  }
  
  type Transport struct {
      url   string
      conn  net.Conn
  }
  
  // connect to url
  func (transport *Transport) Dial(url string) error {
      c, err := net.Dial("unixpacket", url)
      if err != nil {
          return err
      }
      transport.url = url
      transport.conn = c
      return nil
  }
  
  // sending Packet
  func (transport *Transport) Send(p *Packet) bool {
      readBuffer := (p.Data)[p.ReadOffset : p.WriteOffset]
      _, err := transport.conn.Write(readBuffer)
      if err != nil {
          return false
      }
      return true
  }
  
  // receiving Packet
  func (transport *Transport) Recv(p *Packet) bool {
      writeBuffer := (p.Data)[p.WriteOffset :]
      _, err := transport.conn.Read(writeBuffer)
      if err != nil {
          return false
      }
      return true
  }
  
  type Client struct {
      Transport  *Transport
      RecvPacket *Packet
      SendPacket *Packet
  }
  
  // keep checking transport
  func (c *Client) ReadFromTransport() {
      for {
          time.Sleep(20 * time.Millisecond)
          if c.Transport.Recv(c.RecvPacket) == false {
              continue
          }
      }
  }
  </code></pre>
  
  <h2><strong>Question</strong></h2>
  
  <p>Is there a method to have the <code>net.Conn</code> get notified when a new message arriving instead of using a for loop?</p>