From db2b24ae51348665c5a0e61046611cabc3314054 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 28 Apr 2018 16:06:46 +0200 Subject: [PATCH] updated controller implementation (use channels) --- cmd/iface/main.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cmd/iface/main.go b/cmd/iface/main.go index c4cf82e..bed2342 100644 --- a/cmd/iface/main.go +++ b/cmd/iface/main.go @@ -15,20 +15,26 @@ func main(){ serv := ws.CreateServer("0.0.0.0", 4444) /* (2) Bind default controller */ - err := serv.BindDefault(func(c *ws.Client, f *ws.Frame){ - fmt.Printf("Default controller\n") - if f != nil { - fmt.Printf("Received: '%s'\n", f.Buf) + err := serv.BindDefault(func(c *ws.Client, f chan *ws.Frame){ + + fmt.Printf("[default] connected\n") + for frame := range f { + fmt.Printf("[default] received '%s'\n", frame.Buf) } + fmt.Printf("[default] closed\n") + }) if err != nil { panic(err) } /* (3) Bind to URI */ - err = serv.Bind("/channel/./room/./", func(c *ws.Client, f *ws.Frame){ - fmt.Printf("URI controller\n") - if f != nil { - fmt.Printf("Received: '%s'\n", f.Buf) + err = serv.Bind("/channel/./room/./", func(c *ws.Client, f chan *ws.Frame){ + + fmt.Printf("[uri] connected\n") + for frame := range f { + fmt.Printf("[uri] received '%s'\n", frame.Buf) } + fmt.Printf("[uri] closed\n") + }) if err != nil { panic(err) }