title: Bidirectional communication with RPC
body: <p>I am currently implementing an RPC interface (both client and server) about some proprietary product on top of a raw TCP connection. The documentation explicitly demands a JSON-RPC communication and it also adds the following tip:</p>
  
  <pre><code>In &lt;doc number&gt;, antenna and remote device are both server and client
  </code></pre>
  
  <p>In the interface, it appears that the client should be able to receive <code>notifications</code> from the server, simple json message without the need to respond to them.</p>
  
  <p>Basically, it looks like this:</p>
  
  <pre><code>Server ---------------------------------------------------- Client
  
         &lt;------------------------ Client Initiate Connection
         Server acknowledge connection opened --------------&gt;
  
         Server sends a notification about some event-------&gt;
         Server sends another notif. about another event----&gt;
  
         &lt;---------------------------- Client Stop Connection
         Server acknowledge connection stopped -------------&gt;
  </code></pre>
  
  <p>Doing a simple request/response event is easy:</p>
  
  <p>The server looks like this:</p>
  
  <pre><code>func (l *Listener) GetLine(line []byte, ack *bool) error {
      fmt.Println(string(line))
      return nil
  }
  
  func main() {
      addy, err := net.ResolveTCPAddr("tcp", "0.0.0.0:42586")
      inbound, _:= net.ListenTCP("tcp", addy)
      listener := new(Listener)
      rpc.Register(listener)
      rpc.Accept(inbound)
  }
  </code></pre>
  
  <p>And the client is able to call to the server function</p>
  
  <pre><code>client, err := rpc.Dial("tcp", "localhost:42586")
  in := bufio.NewReader(os.Stdin)
  for {
      line, _, err := in.ReadLine()
      var reply bool
      client.Call("Listener.GetLine", line, &amp;reply)
  }
  </code></pre>
  
  <p>In this situation, I do not see how I can send data from the server to the client. How can I do this using the same TCP connection? How can they be both server and client ?</p>