astiudp

package module
v0.0.0-...-76ec099 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2017 License: MIT Imports: 5 Imported by: 2

README

About

Documentation

Index

Constants

View Source
const (
	EventNameStart      = "astiudp.start"
	EventNameDisconnect = "astiudp.disconnect"
)

Event names

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Name    string      `json:"name"`
	Payload interface{} `json:"payload"`
}

Event represents an event sent between a client and a server

type EventRead

type EventRead struct {
	Event
	Payload json.RawMessage `json:"payload"`
}

EventRead overrides Event to allows proper unmarshaling of the payload

type ListenerFunc

type ListenerFunc func(s *Server, eventName string, payload json.RawMessage, addr *net.UDPAddr) error

ListenerFunc represents the listener func

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents an UDP server

func NewServer

func NewServer() *Server

NewServer returns a new UDP server

func (*Server) AddListener

func (s *Server) AddListener(eventType string, l ListenerFunc)

AddListener adds a listener

func (*Server) Close

func (s *Server) Close()

Close closes the server

func (*Server) Init

func (s *Server) Init(addr string) (err error)

Init initializes the server

func (*Server) Listen

func (s *Server) Listen() (err error)

Listen listens to the addr

func (*Server) ListenAndRead

func (s *Server) ListenAndRead()

ListenAndRead listens and reads from the server

func (*Server) Read

func (s *Server) Read() error

Read reads from the server

func (*Server) SetListener

func (s *Server) SetListener(eventType string, l ListenerFunc)

SetListener sets a listener

func (*Server) Write

func (s *Server) Write(eventName string, payload interface{}, addr *net.UDPAddr) (err error)

Write writes an event to the specific addr

Jump to

Keyboard shortcuts

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