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 (*Server) ClientCount ¶
ClientCount returns the number of connected clients
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) RemoteAddr ¶
func (tc *TCPConnection) RemoteAddr() net.Addr
func (*TCPConnection) SetReadDeadline ¶
func (tc *TCPConnection) SetReadDeadline(t time.Time) 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) RemoteAddr ¶
func (wc *WebSocketConnection) RemoteAddr() net.Addr
func (*WebSocketConnection) SetReadDeadline ¶
func (wc *WebSocketConnection) SetReadDeadline(t time.Time) 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