Skip to content

A high performance websocket that uses netpoll with read and write concurrency to allow a high number of concurrent websocket connections.

License

Notifications You must be signed in to change notification settings

blakerouse/concurrent-websocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Concurrent Websocket - Golang

A high performance websocket implementation that uses netpoll with read and write concurrency to allow a high number of concurrent websocket connections.

Prerequisite

Requires Go 1.18 or later, because of golang/go#29257.

Quick start

# assume the following codes in example.go file
$ cat example.go
package main

import (
    "github.com/gin-gonic/gin"
    "github.com/blakerouse/concurrent-websocket"
)

func main() {
    r := gin.Default()

    concurrency := 128
    echo := func(c *websocket.Channel, op websocket.OpCode, data []byte) {
        // echo
        c.Send(op, data)
    }

    wh, _ := websocket.NewHandler(echo, concurrency, concurrency)
    r.GET("/ws", gin.WrapF(wh.UpgradeHandler))

    r.Run() // listen and serve on 0.0.0.0:8080
}
# run example.go and visit 0.0.0.0:8080/ws on browser
$ go run example.go

About

A high performance websocket that uses netpoll with read and write concurrency to allow a high number of concurrent websocket connections.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages