Easy to use websocket library
This is a wrapper for https://github.com/gorilla/websocket
Initialize Hyperion with the default config:
h := hyperion.Default()
Or use a custom config:
h := hyperion.New(&hyperion.Config{ PingInterval: 30 * time.Second, ReadTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second, // ... })
h := hyperion.Default() http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "index.html") }) http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { h.Upgrade(w, r) }) h.HandleMessage(func(c *hyperion.Connection, m hyperion.Message) { // ... handle messages from the client }) log.Fatal(http.ListenAndServe(":8080", nil))
r := gin.Default() h := hyperion.Default() r.GET("/ws", func(ctx *gin.Context) { h.Upgrade(ctx.Writer, ctx.Request) }) h.HandleMessage(func(c *hyperion.Connection, m hyperion.Message) { h.BroadcastBytes(m) }) r.Run(":8080")
h := hyperion.Default() conn, _, _ := h.Dial("ws://localhost:8080/ws", nil) h.HandleMessage(func(conn *hyperion.Connection, m hyperion.Message) { // ... handle messages from the server }) conn.WriteString("Hello World!")
You can find more examples here.
-
Builtin ratelimitter
-
HTTP long polling support
-
Testing with Autobahn test suite