package main import ( "time" "git.xdrm.io/gws/ws" "fmt" ) func main(){ startTime := time.Now().UnixNano() /* (1) Bind WebSocket server */ serv := ws.CreateServer("0.0.0.0", 4444) /* (2) Bind default controller */ 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 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) } /* (4) Launch the server */ err = serv.Launch() if err != nil { fmt.Printf("[ERROR] %s\n", err) return } fmt.Printf("+ elapsed: %1.1f us\n", float32(time.Now().UnixNano()-startTime)/1e3) }