Code Monkey home page Code Monkey logo

Comments (4)

jkralik avatar jkralik commented on August 15, 2024 1

Yes there is such option: WithKeepAlive(nil) https://pkg.go.dev/github.com/go-ocf/go-coap/[email protected]/udp?tab=doc#WithKeepAlive

It is mentioned here: https://tools.ietf.org/html/rfc7252#section-1.2 end of part Reset Message

from go-coap.

jdbruijn avatar jdbruijn commented on August 15, 2024

Thanks for pointing that out, missed that small section of the RFC.

I'm using DTLS, where that option is not available if I'm not mistaken (https://github.com/go-ocf/go-coap/blob/v2.0.2/server.go#L55). The notes you've referred to are specifically for UDP, and I couldn't find a way that I can pass options to the underlying UDP socket of DTLS.
For reference, I'm using go-coap as follows, where it is imported as coap "github.com/go-ocf/go-coap/v2".

	err = coap.ListenAndServeDTLS(
		"udp4",
		fmt.Sprintf(":%v", config.Server.ListenPort),
		&dtlsConfig,
		mux.HandlerFunc(DefaultHandler),
	)

Another question, how should I pass an option, e.g. for keepalive, to dtls.NewServer? I'm relatively new to Go and don't understand how to pass a server option (e.g. for keepalive or blockwiseSZX).

from go-coap.

jkralik avatar jkralik commented on August 15, 2024

So If you want to use options you need to create own ListenAndServe:

func ListenAndServe(config Config) error {
        l, err := net.NewDTLSListener("udp4", fmt.Sprintf(":%v", config.Server.ListenPort), &dtlsConfig)
	if err != nil {
		return err
	}
	defer l.Close()
	s := dtls.NewServer(dtls.WithMux(mux.HandlerFunc(DefaultHandler)), dtls.WithKeepAlive(nil), dtls.WithBlockwise(...))
	return s.Serve(l)
}

from go-coap.

jdbruijn avatar jdbruijn commented on August 15, 2024

Good to know that I just have to create my own function for that, it worked as expected. Thanks for showing the example!

from go-coap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.