updated controller implementation (use channels)

This commit is contained in:
xdrm-brackets 2018-04-28 16:06:46 +02:00
parent a3f72a9bf7
commit db2b24ae51
1 changed files with 14 additions and 8 deletions

View File

@ -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) }