zubairhamed / canopus

CoAP Client/Server implementing RFC 7252 for the Go Language
Apache License 2.0
154 stars 41 forks source link

error looping infinite #62

Closed crazydiamondzgy closed 9 years ago

crazydiamondzgy commented 9 years ago

i wrote a tiny project as https://github.com/crazydiamondzgy/iot-coap-client-c-sdk, and I test with californium server which is right.

when I test with canopus simple server, like this

func main() { server := NewLocalServer()

server.Post("/v1/appid/1", func(req CoapRequest) CoapResponse {
    log.Println("Hello Called")
    PrintMessage(req.GetMessage())
    msg := ContentMessage(req.GetMessage().MessageId, TYPE_ACKNOWLEDGEMENT)
    msg.SetStringPayload("Acknowledged: " + req.GetMessage().Payload.String())
    res := NewResponse(msg, nil)

    return res
})

server.Start()

}

the first time, everything is ok, I closed my tool and reopen to test the second time canopus display error looping infinite as below:

2015/09/18 01:00:47 read udp 0.0.0.0:5683: i/o timeout 2015/09/18 01:00:47 This was a net.OpError with a Timeout 2015/09/18 01:00:47 read udp 0.0.0.0:5683: i/o timeout 2015/09/18 01:00:47 This was a net.OpError with a Timeout 2015/09/18 01:00:47 read udp 0.0.0.0:5683: i/o timeout 2015/09/18 01:00:47 This was a net.OpError with a Timeout 2015/09/18 01:00:47 read udp 0.0.0.0:5683: i/o timeout 2015/09/18 01:00:47 This was a net.OpError with a Timeout 2015/09/18 01:00:47 read udp 0.0.0.0:5683: i/o timeout 2015/09/18 01:00:47 This was a *net.OpError with a Timeout

by the way, I change some code like this to display error code

    readBuf := make([]byte, BUF_SIZE)
for {
    len, addr, err := conn.ReadFromUDP(readBuf)
    if err == nil {

        msgBuf := make([]byte, len)
        copy(msgBuf, readBuf)

        go s.handleMessage(msgBuf, conn, addr)
    } else {
                switch err := err.(type) {

                case net.Error:
                    if err.Timeout() {
                    log.Println("This was a *net.OpError with a Timeout")
                    }
                }

                if err != nil {
                    log.Println(err.Error())
                }
          }
}
zubairhamed commented 9 years ago

Hey thanks for the issue.

Are you running your tests using this example? https://github.com/crazydiamondzgy/iot-coap-client-c-sdk/blob/master/example/test_cli_win32.c

Z

zubairhamed commented 9 years ago

Whoops sorry. Rather obvious that it isn't. The endpoint url is different.

Do you have an example of the rest you ran using uCOAP?

Z

crazydiamondzgy commented 9 years ago

you just compile and run the project file build/vc8/ucoap.sln