I am trying to make a Publish/Subscribe Server using NATS. First step is to connect to the NATS server, but found no working code in the documentation. Here is what I have tried:
package main
import (
"github.com/nats-io/nats.go"
"fmt"
)
func main() {
// Connect to a server
nc, err := nats.Connect("tls://nats.go4webdev.org:4222")
if err!=nil{
fmt.Println(err)
}
fmt.Println(nc)
}
No matter if I instead call
nc, err := nats.Connect("nats://nats.go4webdev.org:4222")
The answer I get from the server:
dial tcp 104.21.65.248:4222: i/o timeout
If I omit the port number, I get this error:
dial tcp [2606:4700:3031::ac43:c3d0]:4222: connect: no route to host
The NATS server is up and running. A port scan shows this:
Port Scanning host: 94.237.X.X
Open TCP Port: 4222
The NATS server on Cloudflare Flexible SSL (proxy)
I run the command service nats status:
> Oct 08 16:02:24 go4webdev.org nats-server[59191]: [59191] 2022/10/08 16:02:24.583853 [ERR] 194.218.x.x:50015 - cid:10 - Client parser ERROR, state=0, i=0: proto='"\x16\x03\x01\x00\xb9\x01\x00\x00\xb5\x03\x01B\xe7\x19\xaa\f\x85\xaf\x81 \xf3\xa6E:)\x88\x93\xe5oKe\x9a"...'
> Oct 08 16:14:00 go4webdev.org nats-server[59191]: [59191] 2022/10/08 16:14:00.470805 [ERR] 127.0.0.1:51756 - cid:12 - Client parser ERROR, state=0, i=0: proto='"GET / HTTP/1.0\r\nHost: localhost:"...'
> Oct 08 16:16:19 go4webdev.org nats-server[59191]: [59191] 2022/10/08 16:16:19.501242 [ERR] 127.0.0.1:51758 - cid:13 - Client parser ERROR, state=0, i=0: proto='"GET / HTTP/1.0\r\nHost: localhost:"...'
> Oct 08 16:18:44 go4webdev.org nats-server[59191]: [59191] 2022/10/08 16:18:44.130856 [ERR] [::1]:41494 - cid:14 - Client parser ERROR, state=0, i=0: proto='"GET / HTTP/1.0\r\nHost: localhost:"...'
Any clue how to connect to the NATS server? What am I doing wrong?