plgd-dev / go-coap

Implementation of CoAP Server & Client in Go

Home Page:https://coap.technology

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A problem with sending large amounts of data using UDP.

MichaIJarosz opened this issue · comments

Hello,
I am testing the sending of a large amount of data using COAP based on UDP. This test is just a preparation before the performance test of the protocol I developed which using COAP as the communication protocol. However, I sometimes get an error that I don't understand. Does anyone perhaps know how to prevent this?

The error:

Error sending request: cannot do bw request: context deadline exceeded, test: 3410

Example code:

func send() {
	for i := 0; i < max; i++ {
		log.Printf("Test: %v", i)
		co, err := udp.Dial("192.168.0.197:5688")
		if err != nil {
			log.Fatalf("Error dialing: %v", err)
		}
		ctx, cancel := context.WithTimeout(context.Background(), time.Second)
		defer cancel()
                // send_message - string with 10kB of random data
		resp, err := co.Post(ctx, path, 0, bytes.NewReader([]byte(send_message)))
		if err != nil {
			log.Fatalf("Error sending request: %v, test: %v", err, i)
		}
		data, _ := io.ReadAll(resp.Body())
		if string(data) != send_message {
			log.Panicf("Bad response!!")
		}
		co.Close()
	}
}

context deadline exceeded means that timeout occurs.

So could you try to increase timeout from 1 sec to 30sec.

ctx, cancel := context.WithTimeout(context.Background(), time.Second * 30)

Btw: there is a limit how much CON coap messages can be send per second (2^16/247) - this limit is defined by deduplication cache.

Ok, Thank you. Now it is clear for me. I reached the limit of CON messages.