wsoding

package module
v0.0.0-...-bd96db4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2025 License: MIT Imports: 11 Imported by: 0

README

wsoding - Tsoding's c3ws library translated to Go

Made it work for majority of the Autobahn Test Cases, so this project can be considered done (with extremely unfriendly API)

Echo Server

./build.sh 

In one terminal:

./build/echo_server

In another terminal

./build/send_client 127.0.0.1 9001 "Hello, World" 

You can also connect to the server from a browser:

firefox ./tools/example_send_client.html

Autobahn Test Suite

docker run -it --rm --net=host \
    -v ${PWD}/autobahn:/config \
    -v ${PWD}/reports:/reports \
    crossbario/autobahn-testsuite \
    wstest -m fuzzingclient -s /config/fuzzingclient.json
firefox ./reports/servers/index.html

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClientHandshakeBadAccept = errors.New("client handshake bad accept")
View Source
var ErrClientHandshakeBadResponse = errors.New("client handshake bad response")

Client Handshake Errors

View Source
var ErrClientHandshakeDuplicateAccept = errors.New("client handshake duplicate accept")
View Source
var ErrClientHandshakeNoAccept = errors.New("client handshake no accept")
View Source
var ErrCloseFrameSent = errors.New("close frame sent")

Connection Errors

View Source
var ErrControlFrameTooBig = errors.New("control frame too big")
View Source
var ErrInvalidUtf8 = errors.New("invalid utf-8")
View Source
var ErrReservedBitsNotNegotiated = errors.New("reserved bits not negotiated")
View Source
var ErrServerHandshakeBadRequest = errors.New("server handshake bad request")

Server Handshake Errors

View Source
var ErrServerHandshakeDuplicateKey = errors.New("server handshake duplicate key")
View Source
var ErrServerHandshakeNoKey = errors.New("server handshake no key")
View Source
var ErrShortUtf8 = errors.New("short utf-8")

utf-8 Errors

View Source
var ErrUnexpectedOpCode = errors.New("unexpected opcode")

Functions

This section is empty.

Types

type WS

type WS struct {
	Sock   *socket.Conn
	Debug  bool
	Client bool
}

func Accept

func Accept(ctx context.Context, sock *socket.Conn) (WS, error)

func Connect

func Connect(ctx context.Context, sock *socket.Conn, host string, endpoint string) (WS, error)

func (*WS) ClientHandshake

func (ws *WS) ClientHandshake(ctx context.Context, host, endpoint string) error

func (*WS) Close

func (ws *WS) Close() error

func (*WS) ReadMessage

func (ws *WS) ReadMessage() (*WSMessage, error)

func (*WS) SendBinary

func (ws *WS) SendBinary(binary []byte) error

func (*WS) SendFrame

func (ws *WS) SendFrame(fin bool, opcode WSOpcode, payload []byte) error

func (*WS) SendMessage

func (ws *WS) SendMessage(kind WSMessageKind, payload []byte) error

func (*WS) SendText

func (ws *WS) SendText(text string) error

func (*WS) ServerHandshake

func (ws *WS) ServerHandshake(ctx context.Context) error

type WSFrameHeader

type WSFrameHeader struct {
	// contains filtered or unexported fields
}

type WSMessage

type WSMessage struct {
	Kind    WSMessageKind
	Payload []byte
}

type WSMessageKind

type WSMessageKind byte
const MessageBIN WSMessageKind = WSMessageKind(OpCodeBIN)
const MessageTEXT WSMessageKind = WSMessageKind(OpCodeTEXT)

type WSOpcode

type WSOpcode byte
const (
	OpCodeCONT  WSOpcode = 0x0
	OpCodeTEXT  WSOpcode = 0x1
	OpCodeBIN   WSOpcode = 0x2
	OpCodeCLOSE WSOpcode = 0x8
	OpCodePING  WSOpcode = 0x9
	OpCodePONG  WSOpcode = 0xA
)

Directories

Path Synopsis
examples
chat command
echo_client command
echo_server command
send_client command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL