title: Unable to send gob data over TCP in Go Programming
body: <p>I have a client server application, using TCP connection</p>
  
  <p>Client:</p>
  
  <pre><code>type Q struct {
      sum int64
  }
  
  type P struct {
      M, N int64
  }
  
  func main() {
      ...
      //read M and N
      ...
      tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
      ...
      var p P
      p.M = M
      p.N = N
      err = enc.Encode(p)
  }
  </code></pre>
  
  <p>Server:</p>
  
  <pre><code>type Q struct {
      sum int64
  }
  
  type P struct {
      M, N int64
  }
  
  func main() {
      ...
      tcpAddr, err := net.ResolveTCPAddr("ip4", service)
      listener, err := net.ListenTCP("tcp", tcpAddr)
      ...
      var connB bytes.Buffer
      dec := gob.NewDecoder(&amp;connB)
      var p P
      err = dec.Decode(p)
      fmt.Printf("{%d, %d}\n", p.M, p.N)
  }
  </code></pre>
  
  <p>The result on serve is {0, 0} because I don't know how to obtain a <code>bytes.Buffer</code> variable from <code>net.Conn</code>.</p>
  
  <p>Is there any way for sending gob variables over TCP ?</p>
  
  <p>If true, how can this be done ? Or there are any alternative in sending numbers over TCP ?</p>
  
  <p>Any help or sample code would really be appreciated.</p>