good morning!!!!

Skip to content
Snippets Groups Projects
Select Git revision
  • 589f1c85b901b06d0058040a02890518b6aa7ab8
  • master default protected
  • v0.2.16-candidate
  • shivam/rpcAddBorTx
  • default-cli-config
  • shivam/minerRecommitFix
  • vcastellm/pos-296-bump-go-version-in-bor-and-heimdall
  • shivam/ethstats-backend-fix
  • v0.2.16-beta1-candidate
  • v0.2.15-beta3-candidate
  • shivam/newCli-IPC
  • v0.3.0-dev
  • checkpoint-whitelist-master
  • shivam/codecov
  • jdkanani/fix-typo-log
  • shivam/hardcoded-spans-v0.2.14
  • shivam/hardcoded-spans
  • shivam/fast-state-sync
  • shivam/fast-state-sync-master
  • gethv1.10.15-merge
  • fix-txpool-2
  • v0.2.14-tmp-span-hotfix
  • v0.2.15-beta2
  • v0.2.15-beta1
  • v0.3.0-beta3
  • v0.3.0-beta2
  • v0.3.0-beta1
  • v0.2.14
  • v0.2.13
  • v0.2.13-beta2
  • v0.2.13-beta1
  • v0.2.12
  • v0.2.12-beta3
  • v0.2.12-beta1
  • v0.2.12-beta2
  • v0.2.11
  • v0.2.10
  • v0.2.10-beta2
  • v0.2.9
  • v0.2.9-beta1
  • v0.2.8
41 results

bor

  • Clone with SSH
  • Clone with HTTPS
  • Forked from github / maticnetwork / bor
    Source project has a limited visibility.

    websocket

    godoc coverage

    websocket is a minimal and idiomatic WebSocket library for Go.

    Install

    go get nhooyr.io/websocket

    Highlights

    Roadmap

    • HTTP/2 #4

    Examples

    For a production quality example that demonstrates the complete API, see the echo example.

    For a full stack example, see the chat example.

    Server

    http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
    	c, err := websocket.Accept(w, r, nil)
    	if err != nil {
    		// ...
    	}
    	defer c.Close(websocket.StatusInternalError, "the sky is falling")
    
    	ctx, cancel := context.WithTimeout(r.Context(), time.Second*10)
    	defer cancel()
    
    	var v interface{}
    	err = wsjson.Read(ctx, c, &v)
    	if err != nil {
    		// ...
    	}
    
    	log.Printf("received: %v", v)
    
    	c.Close(websocket.StatusNormalClosure, "")
    })

    Client

    ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
    defer cancel()
    
    c, _, err := websocket.Dial(ctx, "ws://localhost:8080", nil)
    if err != nil {
    	// ...
    }
    defer c.Close(websocket.StatusInternalError, "the sky is falling")
    
    err = wsjson.Write(ctx, c, "hi")
    if err != nil {
    	// ...
    }
    
    c.Close(websocket.StatusNormalClosure, "")

    Comparison

    gorilla/websocket

    Advantages of gorilla/websocket:

    Advantages of nhooyr.io/websocket:

    golang.org/x/net/websocket

    golang.org/x/net/websocket is deprecated. See golang/go/issues/18152.

    The net.Conn can help in transitioning to nhooyr.io/websocket.

    gobwas/ws

    gobwas/ws has an extremely flexible API that allows it to be used in an event driven style for performance. See the author's blog post.

    However when writing idiomatic Go, nhooyr.io/websocket will be faster and easier to use.