wstcp

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

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

Go to latest
Published: Apr 7, 2021 License: MIT Imports: 4 Imported by: 0

README

WebSocket | TCP

is a Go library for serving WebSocket or TCP clients on the same listener. It can be used as a drop in replacement to add WebSocket support to existing TCP servers.

It automatically detects WebSocket clients, upgrades them and then takes care of headers and control packets.

Usage

ln, _ := net.Listen("tcp", "localhost:9999")
for {
    rawConn, _ := ln.Accept()
    go func() {
        conn, _ := wstcp.New(rawConn)
        // conn can now be used the same way rawConn would be
        // but it can handle WebSocket or raw TCP clients
    }()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WSTCP

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

WSTCP implements io.ReadWriteCloser

func New

func New(conn io.ReadWriteCloser) (*WSTCP, error)

New wraps incoming connection in WSTCP

func (*WSTCP) Close

func (c *WSTCP) Close() error

func (*WSTCP) Read

func (c *WSTCP) Read(b []byte) (int, error)

func (*WSTCP) Write

func (c *WSTCP) Write(b []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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