Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combined Client and Server possible? #133

Closed
c1728p9 opened this issue Jun 23, 2020 · 2 comments
Closed

Combined Client and Server possible? #133

c1728p9 opened this issue Jun 23, 2020 · 2 comments

Comments

@c1728p9
Copy link

c1728p9 commented Jun 23, 2020

It is possible to have a connection where both sides can initiate a request? I'm wanting to use this library to handle LWM2M bootstrapping which needs requests in both directions, but I didn't see a way to do this.

Example LWM2M bootstrap flow:

image

@jkralik
Copy link
Member

jkralik commented Jun 23, 2020

Hi
I think, you need to set a router to the client:

func handleA(w mux.ResponseWriter, r *mux.Message) {
	log.Printf("got message in handleA:  %+v from %v\n", r, w.Client().RemoteAddr())
	err := w.SetResponse(codes.Changed, message.TextPlain, bytes.NewReader([]byte("hello world")))
	if err != nil {
		log.Printf("cannot set response: %v", err)
	}
}
func main() {
        m := mux.NewRouter()
	m.Handle("/0/1", mux.HandlerFunc(handleA))
	co, err := dtls.Dial("localhost:5688", &piondtls.Config{
		PSK: func(hint []byte) ([]byte, error) {
			fmt.Printf("Server's hint: %s \n", hint)
			return []byte{0xAB, 0xC1, 0x23}, nil
		},
		PSKIdentityHint: []byte("Pion DTLS Client"),
		CipherSuites:    []piondtls.CipherSuiteID{piondtls.TLS_PSK_WITH_AES_128_CCM_8},
	}, dtls.WithMux(m))
        ...
}

@c1728p9
Copy link
Author

c1728p9 commented Jun 25, 2020

Thanks for your help @jkralik, with this info I was able to receive the bootstrapping messages I needed.

@c1728p9 c1728p9 closed this as completed Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants