ws/cmd/iface/main.go

45 lines
841 B
Go
Raw Normal View History

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 */
2018-04-26 21:40:53 +00:00
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)
}
})
if err != nil { panic(err) }
/* (3) Bind to URI */
2018-04-26 21:40:53 +00:00
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)
}
})
if err != nil { panic(err) }
/* (4) Launch the server */
2018-04-26 21:40:53 +00:00
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)
}