title: Call golang jsonrpc with curl
body: <p>I have &quot;hello world&quot; rpc service written in golang. It works fine and go jsonrpc client is working. But I need to send request with curl and this example doesn't work:</p>
  <pre><code>curl \
  -X POST \
  -H &quot;Content-Type: application/json&quot; \
  -d '{&quot;id&quot;: 1, &quot;method&quot;: &quot;Test.Say&quot;, &quot;params&quot;: [{&quot;greet&quot;: &quot;world&quot;}]}' \
  http://localhost:1999/_goRPC_
  </code></pre>
  <p>Go accept connection but produce absolutely no result:</p>
  <pre><code>curl: (52) Empty reply from server 
  </code></pre>
  <p>Here my go code:</p>
  <pre><code>package main
  
  import (
    &quot;log&quot;
    &quot;os&quot;
    &quot;time&quot;
    &quot;net&quot;
    &quot;net/rpc&quot;
    &quot;net/rpc/jsonrpc&quot;
  )
  
  // RPC Api structure
  type Test struct {}
  
  // Greet method arguments
  type GreetArgs struct {
    Name string
  }
  
  // Grret message accept object with single param Name
  func (test *Test) Greet(args *GreetArgs, result *string) (error) {
    *result = &quot;Hello &quot; + args.Name
    return nil
  }
  
  // Start server with Test instance as a service
  func startServer(ch chan&lt;- bool, port string) {
    test := new(Test)
  
    server := rpc.NewServer()
    server.Register(test)
  
    listener, err := net.Listen(&quot;tcp&quot;, &quot;:&quot; + port)
  
    if err != nil {
        log.Fatal(&quot;listen error:&quot;, err)
    }
  
    defer listener.Close()
  
    for {
        conn, err := listener.Accept()
  
        if err != nil {
            log.Fatal(err)
        }
  
        go server.ServeCodec(jsonrpc.NewServerCodec(conn))
        ch &lt;- true
    }
  }
  
  // Start client and call Test.Greet method
  func startClient(port string) {
    conn, err := net.Dial(&quot;tcp&quot;, &quot;:&quot; + port)
  
    if err != nil {
        panic(err)
    }
    defer conn.Close()
  
    c := jsonrpc.NewClient(conn)
  
    var reply string
    var args = GreetArgs{&quot;world&quot;}
    err = c.Call(&quot;Test.Greet&quot;, args, &amp;reply)
    if err != nil {
        log.Fatal(&quot;arith error:&quot;, err)
    }
    log.Println(&quot;Result: &quot;, reply)
  }
  
  func main() {
    if len(os.Args) &lt; 2 {
      log.Fatal(&quot;port not specified&quot;)
    }
  
    port := os.Args[1]
    ch := make(chan bool)
  
    go startServer(ch, port)
    time.Sleep(500 * time.Millisecond)
    go startClient(port)
  
    // Produce log message each time connection closes
    for {
      &lt;-ch
      log.Println(&quot;Closed&quot;)
    }
  }
  </code></pre>