title: Simple RPC server will not answer when my client connects
body: <p>I took and adapted the example from <a href="http://golang.org/pkg/net/rpc/" rel="nofollow">Golang RPC</a> to make a simple RPC server as a test run for the real task I want to acheive.  But whatever I have tried I end up with the client getting </p>
  
  <p><code>2014/03/21 13:28:41 dialing: dial-http tcp MYPC:61740: unexpected HTTP response: 404 Not Found</code></p>
  
  <p>I have tried using <code>MYPC:0</code>, <code>127.0.0.1:61470</code>, <code>MYPC:61470</code> and other variants of that theme for the server. Also have tried locally and on two different computers (Note I am using Go 1.2 on Windows). Usually with Go I find it straight-forward to debug, but even reading the source for the rpc pacakge is not helping this time - however I did pick up the trick of :0 giving an available port. </p>
  
  <p>Server can be run by just running the exe, and Client can be run with the port output by the server  <code>chat -c -server=127.0.0.1:8082</code>.</p>
  
  <p>What is actually wrong with the following code?</p>
  
  <pre><code>package main
  
  import (
  "flag"
  "log"
  "net"
  "net/http"
  "net/rpc"
  )
  
  type Chat string
  
  func (t *Chat) Msg(msg string, bytes *int) error {
      *bytes = len(msg)
      return nil
  }
  
  func main() {
  
      server := flag.String("server", "", "Server and port")
      client := flag.Bool("c", false, "Make me a client")
      flag.Parse()
  
      log.Println("Server: ", *server)
  
      if !(*client) {
  
          chat := new(Chat)
          rpc.Register(chat)
          l, e := net.Listen("tcp", *server)
          if e != nil {
              log.Fatal("listen error:", e)
          }
          log.Println(l.Addr().String())
          go rpc.Accept(l)
          http.Serve(l, nil)
  
      } else {
  
          log.Println("Client connecting to", *server)
          // !! The error occurs here
          client, err := rpc.DialHTTP("tcp", *server)
          if err != nil {
              log.Fatal("dialing: ", err)
          }
  
          var reply int
          err = client.Call("Chat.Msg", "Make it so!", &amp;reply)
          if err != nil {
              log.Fatal("chat error:", err)
          }
          log.Println("Msg: returned", reply)
  }
  }
  </code></pre>