Documentation ¶
Overview ¶
Package udps provides functionality to create a UDP Server
Index ¶
- Constants
- type Client
- func (c *Client) Close(code int, reason string)
- func (c *Client) CloseAllStreams()
- func (c *Client) CloseStream(id string)
- func (c *Client) GetStream(id string) (stream *udp.Stream, err error)
- func (c *Client) ID() string
- func (c *Client) OpenStream(metadata map[string]string, data map[string]string) (cstream *udp.Stream, err error)
- func (c *Client) RegisterHandler(mtype network.MessageType, handler MessageHandler) (err error)
- func (c *Client) Send(msg *network.Message) (rmsg *network.Message, err error)
- func (c *Client) String() string
- type ClientConnectedHandler
- type ClientDisconnectedHandler
- type ClientValidateHandler
- type Config
- type MessageHandler
- type Server
- func (s *Server) Close(code int, reason string) (err error)
- func (s *Server) GetClient(id string) (c *Client, err error)
- func (s *Server) GetClientsWithTag(tag string) (clients []*Client)
- func (s *Server) Listen() (err error)
- func (s *Server) RegisterHandler(mtype network.MessageType, handler MessageHandler) (err error)
- func (s *Server) SetClientConnectedHandler(handler ClientConnectedHandler)
- func (s *Server) SetClientDisconnectedHandler(handler ClientDisconnectedHandler)
- func (s *Server) SetStreamHandler(handler udp.StreamHandler)
Constants ¶
const (
KEY_CLIENT_ID = "__CLIENT_ID"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // Metadata Meta *model.ClientData // ID Id string // Remote Address Addr *net.UDPAddr // Tags Tags map[string]string // Closed Status Closed bool // contains filtered or unexported fields }
Client
func (*Client) CloseAllStreams ¶
func (c *Client) CloseAllStreams()
Close all Streams Used when closing the Server
func (*Client) CloseStream ¶
Close the Stream associated with the 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 Client
func (*Client) RegisterHandler ¶
func (c *Client) RegisterHandler(mtype network.MessageType, handler MessageHandler) (err error)
Register Client level MessageHandler
type ClientConnectedHandler ¶
type ClientConnectedHandler func(*Client)
Called on initial client connection
type ClientDisconnectedHandler ¶
type ClientDisconnectedHandler func(*Client)
Called when a client disconnects
type ClientValidateHandler ¶
type ClientValidateHandler func(*net.UDPAddr, *model.ClientValidateData) (cd *model.ClientData, err error)
Called when a new client connects to the server
type Config ¶
type Config struct { // Log Tag Tag string // Listen Address Addr *net.UDPAddr // Protobuf Unmarshaler Unmarshaler network.ChannelUnmarshaler // Use QUIC Datagrams Datagrams bool // TLS Config TLS *tls.Config // QUIC Config Quic *quic.Config // contains filtered or unexported fields }
UDP Server Config
func (*Config) MaxStreams ¶
Maximum number of streams per connection
func (*Config) Unmarshalers ¶
func (c *Config) Unmarshalers() (unmarshalers []network.ChannelUnmarshaler)
Protobuf Unmarshalers
func (*Config) UseDatagram ¶
Whether to use Datagram mode for QUIC
type MessageHandler ¶
Called when a client sends a message
type Server ¶
type Server struct { // Config Cfg Config // Client Validation Handler ClientValidateHandler ClientValidateHandler // New Stream Handler StreamHandler udp.StreamHandler // UDP Connection UDPConn *net.UDPConn // Exit Channel Exit chan bool // Server Closed Status Closed bool // contains filtered or unexported fields }
Server
func New ¶
func New( log *logrus.Logger, cfg Config, clientValidateHandler ClientValidateHandler, ) (s *Server, err error)
Creates a Server
func NewWithConnection ¶
func NewWithConnection( log *logrus.Logger, cfg Config, udpConn *net.UDPConn, clientValidateHandler ClientValidateHandler, ) (s *Server, err error)
Creates a Server using an existing net.UDPConn connection
func (*Server) GetClientsWithTag ¶
Get Clients by Tag
func (*Server) RegisterHandler ¶
func (s *Server) RegisterHandler(mtype network.MessageType, handler MessageHandler) (err error)
Register a MessageType Handler
func (*Server) SetClientConnectedHandler ¶
func (s *Server) SetClientConnectedHandler(handler ClientConnectedHandler)
Set Client Connected handler
func (*Server) SetClientDisconnectedHandler ¶
func (s *Server) SetClientDisconnectedHandler(handler ClientDisconnectedHandler)
Set Client Disconnect Handler
func (*Server) SetStreamHandler ¶
func (s *Server) SetStreamHandler(handler udp.StreamHandler)
Set New Stream Handler