client

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 11 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 provides a basic struct of Client object

func NewClient

func NewClient(
	callsign string, passcode string,
	mode Mode, protocol Protocol,
	host string, port int,
	options ...Option,
) *Client

NewClient creates a new APRS client

func (*Client) Callsign

func (c *Client) Callsign() string

func (*Client) Close

func (c *Client) Close()

Close a client

func (*Client) Connect

func (c *Client) Connect() error

Connect to an APRS server.

For TCP the client opens a persistent stream, performs the login handshake and starts the receive/heartbeat goroutines. For UDP it opens a connected datagram socket used in "UDP submit" mode: there is no login handshake or receive loop; instead every SendPacket datagram is prefixed with the login line (see SendPacket).

func (*Client) Filter

func (c *Client) Filter() string

func (*Client) GetStats

func (c *Client) GetStats() Stats

GetStats returns the current statistics

func (*Client) Host

func (c *Client) Host() string

func (*Client) Mode

func (c *Client) Mode() Mode

func (*Client) Port

func (c *Client) Port() int

func (*Client) Protocol

func (c *Client) Protocol() Protocol

func (*Client) RemoteAddr added in v1.3.0

func (c *Client) RemoteAddr() string

RemoteAddr returns the resolved remote address of the active connection (e.g. "44.135.0.1:10152"), or "" if not connected. Unlike Host(), which is the configured (possibly DNS) hostname, this reflects the actual IP a rotating DNS name resolved to for the current session.

func (*Client) ResetStats

func (c *Client) ResetStats()

ResetStats resets all statistics to zero

func (*Client) SendPacket

func (c *Client) SendPacket(packet string) error

SendPacket sends an APRS packet.

For TCP the packet is written to the stream terminated by CRLF. For UDP (submit mode) the datagram is the login line followed by the packet, both CRLF-terminated, so the server can authenticate and inject each datagram independently (qAU).

func (*Client) Server

func (c *Client) Server() string

func (*Client) ServerID added in v1.3.0

func (c *Client) ServerID() string

ServerID returns the upstream server's callsign, parsed from its logresp line (empty until login completes).

func (*Client) Up

func (c *Client) Up() bool

func (*Client) Uptime

func (c *Client) Uptime() time.Time

func (*Client) Wait

func (c *Client) Wait()

Wait blocks until the client is permanently done, i.e. the link has dropped and the client will not (re)connect on its own. It returns when either:

  • Close() is called, or
  • the connection dropped and the client exhausted its reconnection attempts (including the WithRetryTimes(0) case, where the client does no internal reconnection at all — see signalDone in receivePackets).

This is the contract relied on by an external supervisor (e.g. the aprsgo uplink manager) that owns reconnection: it sets WithRetryTimes(0) and uses Wait() to learn when the link is down so it can dial a fresh connection.

type Mode

type Mode string

Mode is a ENUM type for client mode

const (
	Fullfeed Mode = "fullfeed"
	IGate    Mode = "igate"
)

type Option

type Option func(*Client)

Option provides a basic option type

func WithBufSize added in v1.2.4

func WithBufSize(bufSize int) Option

WithBufSize sets a custom buf size for reader

func WithFilter

func WithFilter(filter string) Option

WithFilter sets a filter to the client

func WithHandler

func WithHandler(handler func(packet string)) Option

WithHandler sets default packet handler to custom

func WithKeepAlive added in v1.4.0

func WithKeepAlive(idle, interval time.Duration, count int) Option

WithKeepAlive enables TCP keepalive on the connection: probing starts after the socket has been idle for idle, probes are sent every interval, and the link is dropped after count failed probes. It has no effect on UDP.

func WithLocalAddr added in v1.4.0

func WithLocalAddr(v4, v6 string) Option

WithLocalAddr binds the local source address for outbound connections. v4 is used when connecting to an IPv4 remote, v6 for IPv6; either may be empty to let the OS choose for that family.

func WithLogger

func WithLogger(logger aprsutils.Logger) Option

WithLogger sets default logger to custom

func WithReadTimeout added in v1.4.0

func WithReadTimeout(d time.Duration) Option

WithReadTimeout sets the per-read deadline applied while receiving from the server. A zero or negative value keeps the built-in default.

func WithRetryTimes

func WithRetryTimes(retryTimes int) Option

WithRetryTimes sets how many times the client tries to reconnect itself after the link drops. Set it to 0 to disable internal reconnection entirely: in that mode the client does not reconnect on its own, and when the link drops it releases Wait() so an external supervisor can dial a fresh connection (see Wait for the full contract).

func WithSoftwareAndVersion

func WithSoftwareAndVersion(software string, version string) Option

WithSoftwareAndVersion sets default software name and version to custom

type Protocol

type Protocol string

Protocol is a ENUM type for client protocol

const (
	TCP Protocol = "tcp"
	UDP Protocol = "udp"
)

type Stats

type Stats struct {
	TotalSentBytes  uint64
	TotalRecvBytes  uint64
	CurrentSentRate uint64
	CurrentRecvRate uint64
	PacketsSent     uint64
	PacketsReceived uint64
	ConnectionTime  time.Duration
	LastActivity    time.Time
}

Stats contains statistics for the client

Jump to

Keyboard shortcuts

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