server

package
v0.0.0-...-2f4e5ef Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Zlib Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a connected client

type Connection

type Connection interface {
	// RemoteAddr returns the remote address
	RemoteAddr() net.Addr

	// Write sends binary data to the client
	Write(data []byte) (int, error)

	// Read receives binary data from the client
	Read(buf []byte) (int, error)

	// Close closes the connection
	Close() error

	// SetReadDeadline sets the read deadline
	SetReadDeadline(t time.Time) error
}

Connection represents a client connection (TCP or WebSocket)

type Option

type Option func(*Server)

Option configures a Server created by New.

func WithTLS

func WithTLS(cert tls.Certificate) Option

WithTLS supplies the TLS certificate used for the WebTransport endpoint. Providing it is what enables WebTransport; without it the server serves only TCP and WebSocket.

type Server

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

Server represents a TCP chat server

func New

func New(address string, opts ...Option) *Server

New creates a new Server instance

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the server's listening address

func (*Server) ClientCount

func (s *Server) ClientCount() int

ClientCount returns the number of connected clients

func (*Server) Start

func (s *Server) Start() error

Start starts the TCP server

func (*Server) Stop

func (s *Server) Stop()

Stop stops the server

type TCPConnection

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

TCPConnection wraps a net.Conn for TCP connections

func NewTCPConnection

func NewTCPConnection(conn net.Conn) *TCPConnection

NewTCPConnection creates a new TCPConnection

func NewTCPConnectionWithReader

func NewTCPConnectionWithReader(conn net.Conn, reader *bufio.Reader) *TCPConnection

NewTCPConnectionWithReader creates a new TCPConnection with a buffered reader This is used when we've already peeked at the connection for protocol detection

func (*TCPConnection) Close

func (tc *TCPConnection) Close() error

func (*TCPConnection) Read

func (tc *TCPConnection) Read(buf []byte) (int, error)

func (*TCPConnection) RemoteAddr

func (tc *TCPConnection) RemoteAddr() net.Addr

func (*TCPConnection) SetReadDeadline

func (tc *TCPConnection) SetReadDeadline(t time.Time) error

func (*TCPConnection) Write

func (tc *TCPConnection) Write(data []byte) (int, error)

type WebSocketConnection

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

WebSocketConnection wraps a net.Conn for WebSocket connections using gobwas/ws

func NewWebSocketConnection

func NewWebSocketConnection(conn net.Conn) *WebSocketConnection

NewWebSocketConnection creates a new WebSocketConnection

func (*WebSocketConnection) Close

func (wc *WebSocketConnection) Close() error

func (*WebSocketConnection) Read

func (wc *WebSocketConnection) Read(buf []byte) (int, error)

func (*WebSocketConnection) RemoteAddr

func (wc *WebSocketConnection) RemoteAddr() net.Addr

func (*WebSocketConnection) SetReadDeadline

func (wc *WebSocketConnection) SetReadDeadline(t time.Time) error

func (*WebSocketConnection) Write

func (wc *WebSocketConnection) Write(data []byte) (int, error)

type WebTransportConnection

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

WebTransportConnection wraps a WebTransport session and its single bidirectional stream so the chat session can be treated as a byte stream, exactly like TCP. Framing follows the same assumption as TCP: one Read is expected to yield one whole protobuf message.

func NewWebTransportConnection

func NewWebTransportConnection(
	session *webtransport.Session,
	stream *webtransport.Stream,
) *WebTransportConnection

NewWebTransportConnection creates a new WebTransportConnection from an upgraded session and the bidirectional stream that carries the chat session.

func (*WebTransportConnection) Close

func (c *WebTransportConnection) Close() error

Close closes the stream and the session. The session is closed as well as the stream so the underlying QUIC connection is torn down and no goroutine (the HTTP handler blocked on the session context, or the session's capsule reader) lingers after a client disconnects.

func (*WebTransportConnection) Read

func (c *WebTransportConnection) Read(buf []byte) (int, error)

func (*WebTransportConnection) RemoteAddr

func (c *WebTransportConnection) RemoteAddr() net.Addr

func (*WebTransportConnection) SetReadDeadline

func (c *WebTransportConnection) SetReadDeadline(t time.Time) error

func (*WebTransportConnection) Write

func (c *WebTransportConnection) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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