Help us shape the future of Go! Take the 2026 Go Developer Survey

stream_datagram

package
v0.57.13 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package stream_datagram forwards UDP packets over an established peer message stream. Each stream has one fixed UDP peer and one socket; peer authentication and stream admission belong to the caller's existing link/session authority.

Index

Constants

View Source
const MaxPacketSize = 65507

MaxPacketSize bounds packets to the maximum IPv4 UDP payload.

Each packet is sent as one message on the peer stream, so a lost packet never delays the ones after it. A packet too large for one message falls back to the reliable control stream as a two-byte big-endian payload length followed by exactly that many bytes. Empty datagrams are preserved. Packets may arrive out of order, as UDP permits.

Variables

This section is empty.

Functions

func Forward

func Forward(ctx context.Context, socket *net.UDPConn, peer *net.UDPAddr, peerStream stream.MessageStream) error

Forward owns socket and peerStream until it returns, including on failure. socket must be unconnected and peer is the only permitted UDP sender and destination. Other local senders are ignored. Cancellation or either side failing closes both resources and waits for every forwarding pump to finish. The caller binds a fresh socket per player/session; never share this socket with another Forward call. Only admitted sessions should reach this API.

func ForwardLocal

func ForwardLocal(ctx context.Context, socket *net.UDPConn, peerStream stream.MessageStream) error

ForwardLocal forwards one local application's UDP association. socket must be bound to loopback. Its first sender becomes the fixed peer for this stream; packets from other senders are ignored. The first packet is retained and forwarded. The caller owns admission of the remote stream and gives only its selected local application this endpoint. Cancellation closes both resources.

func ForwardTarget

func ForwardTarget(ctx context.Context, target *net.UDPAddr, peerStream stream.MessageStream) error

ForwardTarget allocates a dedicated upstream UDP association for one peer stream, then forwards to a fixed service endpoint. Separate calls produce separate source ports at the service, so replies cannot cross player streams. It owns peerStream even if binding the socket fails.

Types

This section is empty.

Jump to

Keyboard shortcuts

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