udpc

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package udpc provides functionality to create a UDP Client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CanConnect

type CanConnect func(tries int) bool

Called to determine whether to connect to a Server

type CanReconnect

type CanReconnect func(tries int) bool

Called to determine whether to reconnect to a Server

type Client

type Client struct {
	// Config
	Cfg Config

	// Listen Address
	Addr *net.UDPAddr
	// UDP Connection
	// It's exposed as it's needed in the p2pc package
	UDPConn *net.UDPConn

	// ID
	Id string

	// Metadata
	Data *model.ClientData

	// Connected Status
	Connected bool
	// Exit Channel
	Exit chan bool
	// Closed Status
	Closed bool
	// contains filtered or unexported fields
}

Client

func New

func New(log *logrus.Logger, cfg Config) (c *Client, err error)

Creates a new Client

func NewWithConnection

func NewWithConnection(log *logrus.Logger, cfg Config, addr *net.UDPAddr, udpConn *net.UDPConn) (c *Client, err error)

Creates a new Client using an existing net.UDPConn connection

func (*Client) Close

func (c *Client) Close(code int, reason string)

Close connection with Server

func (*Client) CloseAllStreams

func (c *Client) CloseAllStreams()

Close all Streams Used when closing the Client

func (*Client) CloseStream

func (c *Client) CloseStream(id string)

Close the Stream associated with the ID

func (*Client) Connect

func (c *Client) Connect() (err error)

Connect to Server

func (*Client) GetStream

func (c *Client) GetStream(id string) (stream *udp.Stream, err error)

Return the Stream associated with the ID

func (*Client) ID

func (c *Client) ID() string

Client ID

func (*Client) OpenStream

func (c *Client) OpenStream(metadata map[string]string, data map[string]string) (cstream *udp.Stream, err error)

Open a new Stream to the Server

func (*Client) RegisterHandler

func (c *Client) RegisterHandler(mtype network.MessageType, handler MessageHandler) (err error)

Register a MessageType Handler

func (*Client) SearchClients

func (c *Client) SearchClients(params *model.ClientSearch) (clients []string, err error)

Search for Clients based on certain parameters

func (*Client) Send

func (c *Client) Send(msg *network.Message) (rmsg *network.Message, err error)

Send a Message to the Server

func (*Client) SetCanConnectHandler

func (c *Client) SetCanConnectHandler(handler CanConnect)

Set CanConnect Handler

func (*Client) SetCanReconnectHandler

func (c *Client) SetCanReconnectHandler(handler CanReconnect)

Set CanReconnect Handler

func (*Client) SetClosedHandler

func (c *Client) SetClosedHandler(handler ClosedHandler)

Set Closed Handler

func (*Client) SetConnectedHandler

func (c *Client) SetConnectedHandler(handler ConnectedHandler)

Set Connected Handler

func (*Client) SetDisconnectedHandler

func (c *Client) SetDisconnectedHandler(handler DisconnectedHandler)

Set Disconnected Handler

func (*Client) SetStreamHandler

func (c *Client) SetStreamHandler(handler udp.StreamHandler)

Set New Stream Handler

func (*Client) String

func (c *Client) String() string

Stringify

type ClosedHandler

type ClosedHandler func(reason string)

Called when client is closed

type Config

type Config struct {
	// Log Tag
	Tag string
	// Server Address
	ServerAddr *net.UDPAddr
	// No. of times to try to connect
	ConnectTries int
	// No. of times to try to reconnect
	ReconnectTries int
	// Use QUID Datagram
	Datagrams   bool
	Unmarshaler network.ChannelUnmarshaler

	// Server Token
	Token string
	// Metadata
	Data map[string]string

	// TLS Config
	TLS *tls.Config
	// QUIC Config
	Quic *quic.Config
	// contains filtered or unexported fields
}

UDP Client Config

func (*Config) MaxStreams

func (c *Config) MaxStreams() int16

Maximum number of streams per connection

func (*Config) Unmarshalers

func (c *Config) Unmarshalers() (unmarshalers []network.ChannelUnmarshaler)

Protobuf Unmarshalers

func (*Config) UseDatagram

func (c *Config) UseDatagram() bool

Whether to use Datagram mode for QUIC

type ConnectedHandler

type ConnectedHandler func(reconnect bool)

Called on connection to the server

type DisconnectedHandler

type DisconnectedHandler func()

Called on disconnection from a Server

type MessageHandler

type MessageHandler func(*Client, *network.Message)

Called when a Server sends a message

Jump to

Keyboard shortcuts

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