[golang] CoAP server over UDP doesn't work (TCP does)

Are there any examples which I can look at for what a correct implementation of a CoAP server running in fly.io over UDP would look like. I am particularly interested into knowing if there is some extra configuration I need to do other than what is suggested in the docs.

Example

Go to the Simple Example in this repo, and deploy the server to fly.io
then call with the client code the server, you should get the error:

"(*fmt.wrapError)(0xc000292020)(cannot write request: cannot write request: context deadline exceeded)"

Update

Just to verify I also implemented the CoAP server over TCP (check commented code in this example) and the implementation just works.

I really think there is something wrong happening with the UDP service communication. I don’t know what internally your reverse proxy does but I will really appreciate some help

Hey there, did you try listening on fly-global-services:5688 as documented here? This is required for UDP to operate correctly on Fly.io.

Yes I did. I also opt-in for the dedicated IPv4

Can you think of any other debugging tips I can try to do? :smile:

The client sends data over CoAP to the deployed instance in fly.io;
I can observe the logs from the dashboard and I see that the server gets the message, but then the client gets an error that it can’t write to the request; to me this seems as if the server can be reached but can’t acknowledge the messages and the client assumes the message was never responded to.

For fact I did verify that the implementation is correct and it works in a different environment (local network)

Server code

func handleMessage(w mux.ResponseWriter, r *mux.Message) {
	fmt.Println("Hello world, I will try to write to connection", r.Message)
	err := w.SetResponse(codes.POST, message.TextPlain, bytes.NewReader([]byte("hello world")))
	if err != nil {
		log.Printf("cannot set response: %v", err)
	}
}

Logs

2024-05-28T15:25:33.873 app[7843d45b2d2598] ams [info] Hello world, I will try to write to connection Code: POST, Token: 58a904b98b6c4ddc, Path: /a, ContentFormat: text/plain; charset=utf-8, Type: Confirmable, MessageID: 21626, PayloadLen: 3

The “cannot set response error” log is not printed but on the client code

Client code

    // ...
	co, err := udp.Dial(fmt.Sprintf("%s:%s", c.Host, c.Port))
	if err != nil {
		return err
	}
	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
	defer cancel()
	if _, err := co.Post(ctx, "/a", message.MediaType(message.TextPlain), data); err != nil {
		// this errors to:
		// "cannot write request: cannot write request: context deadline exceeded"
		return err
	}
	// ...

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.