Skip to content
This repository was archived by the owner on Oct 12, 2026. It is now read-only.
demskiePublic archive

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

websocket

High performance websocket server

Example

package main

import (
    "github.com/demskie/websocket"
    xwebsocket "golang.org/x/net/websocket"
)

manager, err := websocket.NewManager("127.0.0.1:12345", nil)
if err != nil {
    panic(err)
}

manager.SetReadPoolSize(1024)
manager.SetUpgradeTimeout(10 * time.Second)
manager.SetHandler(func(s *Session) {
    buf := &bytes.Buffer{}
    for i := 0; i < 123; i++ {
        _, err := s.Receive(buf, 0)
        if err != nil {
            panic(err)
        }
        s.Write(buf.Bytes())
    }
})

url := "ws://127.0.0.1:12345"
origin := "http://localhost"
ws, err := xwebsocket.Dial(url, "", origin)
if err != nil {
    panic(err)
}

n, err := ws.Write([]byte("hello, world!\n"))
if err != nil {
    panic(err)
}

payload := make([]byte, n)
_, err = ws.Read(payload)
if err != nil {
    panic(err)
}

if bytes.Compare(payload, []byte("hello, world!\n")) != 0 {
    panic(string(payload))
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

⌂ 换网址