-2

I'm trying to use random.org to generate random numbers in my go program. It seems like I need to establish a json-rpc connection, so I'm trying to use the method jsonrpc.Dial(network, adress). All the api says is that I need to invoke https://api.random.org/json-rpc/2/invoke; what should I use as the network (and what is a network)?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
lolad
  • 321
  • 6
  • 13

1 Answers1

-1

If you look at the source code for jsonrpc.Dial, you see that the network argument is passed straight on to net.Dial, whose godoc explains:

Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix", "unixgram" and "unixpacket".

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • So which one should I use? I don't really understand networks, sorry. I've tried `jsonrpc.Dial("tpc", "api.random.org/json-rpc/2/invoke:https")`, and variations but nothing seems to work, all resulting in `panic: dial tcp: lookup api.random.org/json-rpc/2/invoke: no such host` – lolad Aug 10 '20 at 11:46
  • 2
    @lolad, use `Dial("tcp", "api.random.org:443")` for HTTPS. `api.random.org/json-rpc/2/invoke` is not a valid hostname. – Peter Aug 10 '20 at 11:53
  • Thanks, it seems to get through now at least, but can you please explain the 443? And also discarding the `json-rpc/2/invoke`, surely the methods won't work correctly? – lolad Aug 10 '20 at 12:08
  • 443 is the port for HTTPS. You probably need to do some basic reading about HTTP. We can't really give you a complete primer on the basics of IP and HTTP in comments (or answers) on SO. – Jonathan Hall Aug 10 '20 at 12:18