Documentation
¶
Index ¶
- func Client(conn *net.UDPConn, opts ...DialOption) *client.ClientConn
- func Dial(target string, opts ...DialOption) (*client.ClientConn, error)
- type BlockwiseFactoryFunc
- type BlockwiseOpt
- type CloseSocketOpt
- type ContextOpt
- type DialOption
- type DialerOpt
- type ErrorFunc
- type ErrorsOpt
- type EventFunc
- type GetMIDFunc
- type GoPoolFunc
- type GoPoolOpt
- type HandlerFunc
- type HandlerFuncOpt
- type InactivityMonitorOpt
- type KeepAliveOpt
- type MaxMessageSizeOpt
- type MessagePoolOpt
- type NetOpt
- type OnNewClientConnFunc
- type OnNewClientConnOpt
- type PeriodicRunnerOpt
- type Server
- func (s *Server) Discover(ctx context.Context, address, path string, ...) error
- func (s *Server) DiscoveryRequest(req *pool.Message, address string, ...) error
- func (s *Server) NewClientConn(addr *net.UDPAddr) (*client.ClientConn, error)
- func (s *Server) Serve(l *coapNet.UDPConn) error
- func (s *Server) Stop()
- type ServerOption
- type Session
- func (s *Session) AddOnClose(f EventFunc)
- func (s *Session) Close() error
- func (s *Session) Context() context.Context
- func (s *Session) Done() <-chan struct{}
- func (s *Session) LocalAddr() net.Addr
- func (s *Session) MaxMessageSize() uint32
- func (s *Session) RemoteAddr() net.Addr
- func (s *Session) Run(cc *client.ClientConn) (err error)
- func (s *Session) SetContextValue(key interface{}, val interface{})
- func (s *Session) WriteMessage(req *pool.Message) error
- func (s *Session) WriteMulticastMessage(req *pool.Message, address *net.UDPAddr, opts ...coapNet.MulticastOption) error
- type TransmissionOpt
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Client ¶
func Client(conn *net.UDPConn, opts ...DialOption) *client.ClientConn
Client creates client over udp connection.
func Dial ¶
func Dial(target string, opts ...DialOption) (*client.ClientConn, error)
Dial creates a client connection to the given target.
Types ¶
type BlockwiseFactoryFunc ¶
type BlockwiseOpt ¶
type BlockwiseOpt struct {
// contains filtered or unexported fields
}
BlockwiseOpt network option.
func WithBlockwise ¶
WithBlockwise configure's blockwise transfer.
type CloseSocketOpt ¶ added in v2.1.0
type CloseSocketOpt struct { }
CloseSocketOpt close socket option.
func WithCloseSocket ¶ added in v2.1.0
func WithCloseSocket() CloseSocketOpt
WithCloseSocket closes socket at the close connection.
type ContextOpt ¶
type ContextOpt struct {
// contains filtered or unexported fields
}
ContextOpt handler function option.
func WithContext ¶
func WithContext(ctx context.Context) ContextOpt
WithContext set's parent context of server.
type DialOption ¶
type DialOption interface {
// contains filtered or unexported methods
}
A DialOption sets options such as credentials, keepalive parameters, etc.
type DialerOpt ¶ added in v2.2.0
type DialerOpt struct {
// contains filtered or unexported fields
}
DialerOpt dialer option.
func WithDialer ¶ added in v2.2.0
WithDialer set dialer for dial.
type ErrorsOpt ¶
type ErrorsOpt struct {
// contains filtered or unexported fields
}
ErrorsOpt errors option.
func WithErrors ¶
WithErrors set function for logging error.
type GetMIDFunc ¶
type GetMIDFunc = func() uint16
type GoPoolFunc ¶
type GoPoolFunc = func(func()) error
type GoPoolOpt ¶
type GoPoolOpt struct {
// contains filtered or unexported fields
}
GoPoolOpt gopool option.
func WithGoPool ¶
func WithGoPool(goPool GoPoolFunc) GoPoolOpt
WithGoPool sets function for managing spawning go routines for handling incoming request's. Eg: https://github.com/panjf2000/ants.
type HandlerFunc ¶
type HandlerFunc = func(*client.ResponseWriter, *pool.Message)
The HandlerFunc type is an adapter to allow the use of ordinary functions as COAP handlers.
type HandlerFuncOpt ¶
type HandlerFuncOpt struct {
// contains filtered or unexported fields
}
HandlerFuncOpt handler function option.
func WithHandlerFunc ¶
func WithHandlerFunc(h HandlerFunc) HandlerFuncOpt
WithHandlerFunc set handle for handling request's.
func WithMux ¶
func WithMux(m mux.Handler) HandlerFuncOpt
WithMux set's multiplexer for handle requests.
type InactivityMonitorOpt ¶ added in v2.3.0
type InactivityMonitorOpt struct {
// contains filtered or unexported fields
}
InactivityMonitorOpt notifies when a connection was inactive for a given duration.
func WithInactivityMonitor ¶ added in v2.3.0
func WithInactivityMonitor(duration time.Duration, onInactive inactivity.OnInactiveFunc) InactivityMonitorOpt
WithInactivityMonitor set deadline's for read operations over client connection.
type KeepAliveOpt ¶
type KeepAliveOpt struct {
// contains filtered or unexported fields
}
KeepAliveOpt keepalive option.
func WithKeepAlive ¶
func WithKeepAlive(maxRetries uint32, timeout time.Duration, onInactive inactivity.OnInactiveFunc) KeepAliveOpt
WithKeepAlive monitoring's client connection's.
type MaxMessageSizeOpt ¶
type MaxMessageSizeOpt struct {
// contains filtered or unexported fields
}
MaxMessageSizeOpt handler function option.
func WithMaxMessageSize ¶
func WithMaxMessageSize(maxMessageSize uint32) MaxMessageSizeOpt
WithMaxMessageSize limit size of processed message.
type MessagePoolOpt ¶ added in v2.5.0
type MessagePoolOpt struct {
// contains filtered or unexported fields
}
ConnectionCacheOpt network option.
func WithMessagePool ¶ added in v2.5.0
func WithMessagePool(messagePool *pool.Pool) MessagePoolOpt
WithMessagePool configure's message pool for acquire/releasing coap messages
type NetOpt ¶
type NetOpt struct {
// contains filtered or unexported fields
}
NetOpt network option.
func WithNetwork ¶
WithNetwork define's udp version (udp4, udp6, udp) for client.
type OnNewClientConnFunc ¶
type OnNewClientConnFunc = func(cc *client.ClientConn)
type OnNewClientConnOpt ¶
type OnNewClientConnOpt struct {
// contains filtered or unexported fields
}
OnNewClientConnOpt network option.
func WithOnNewClientConn ¶
func WithOnNewClientConn(onNewClientConn OnNewClientConnFunc) OnNewClientConnOpt
WithOnNewClientConn server's notify about new client connection.
type PeriodicRunnerOpt ¶ added in v2.5.0
type PeriodicRunnerOpt struct {
// contains filtered or unexported fields
}
PeriodicRunnerOpt function which is executed in every ticks
func WithPeriodicRunner ¶ added in v2.5.0
func WithPeriodicRunner(periodicRunner periodic.Func) PeriodicRunnerOpt
WithPeriodicRunner set function which is executed in every ticks.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(opt ...ServerOption) *Server
func (*Server) Discover ¶
func (s *Server) Discover(ctx context.Context, address, path string, receiverFunc func(cc *client.ClientConn, resp *pool.Message), opts ...coapNet.MulticastOption) error
Discover sends GET to multicast or unicast address and waits for responses until context timeouts or server shutdown. For unicast there is a difference against the Dial. The Dial is connection-oriented and it means that, if you send a request to an address, the peer must send the response from the same address where was request sent. For Discover it allows the client to send a response from another address where was request send. By default it is sent over all network interfaces and all compatible source IP addresses with hop limit 1. Via opts you can specify the network interface, source IP address, and hop limit.
Example ¶
package main import ( "context" "fmt" "io/ioutil" "log" "sync" "time" "github.com/plgd-dev/go-coap/v2/net" "github.com/plgd-dev/go-coap/v2/udp" "github.com/plgd-dev/go-coap/v2/udp/client" "github.com/plgd-dev/go-coap/v2/udp/message/pool" ) func main() { l, err := net.NewListenUDP("udp", "") if err != nil { log.Fatal(err) } defer l.Close() var wg sync.WaitGroup defer wg.Wait() s := udp.NewServer() defer s.Stop() wg.Add(1) go func() { defer wg.Done() errS := s.Serve(l) if errS != nil { log.Println(errS) } }() ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() err = s.Discover(ctx, "224.0.1.187:5683", "/oic/res", func(cc *client.ClientConn, res *pool.Message) { data, errR := ioutil.ReadAll(res.Body()) if errR != nil { log.Fatal(errR) } fmt.Printf("%v", data) }) if err != nil { log.Fatal(err) } }
Output:
func (*Server) DiscoveryRequest ¶
func (s *Server) DiscoveryRequest(req *pool.Message, address string, receiverFunc func(cc *client.ClientConn, resp *pool.Message), opts ...coapNet.MulticastOption) error
DiscoveryRequest sends request to multicast/unicast address and wait for responses until request timeouts or server shutdown. For unicast there is a difference against the Dial. The Dial is connection-oriented and it means that, if you send a request to an address, the peer must send the response from the same address where was request sent. For Discover it allows the client to send a response from another address where was request send. By default it is sent over all network interfaces and all compatible source IP addresses with hop limit 1. Via opts you can specify the network interface, source IP address, and hop limit.
func (*Server) NewClientConn ¶ added in v2.6.0
func (*Server) Serve ¶
Example ¶
package main import ( "log" "github.com/plgd-dev/go-coap/v2/net" "github.com/plgd-dev/go-coap/v2/udp" ) func main() { l, err := net.NewListenUDP("udp", "0.0.0.0:5683") if err != nil { log.Fatal(err) } defer l.Close() s := udp.NewServer() defer s.Stop() log.Fatal(s.Serve(l)) }
Output:
type ServerOption ¶
type ServerOption interface {
// contains filtered or unexported methods
}
A ServerOption sets options such as credentials, codec and keepalive parameters, etc.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
func (*Session) AddOnClose ¶
func (*Session) Done ¶
func (s *Session) Done() <-chan struct{}
Done signalizes that connection is not more processed.
func (*Session) MaxMessageSize ¶
func (*Session) RemoteAddr ¶
func (*Session) SetContextValue ¶ added in v2.1.0
func (s *Session) SetContextValue(key interface{}, val interface{})
SetContextValue stores the value associated with key to context of connection.
func (*Session) WriteMulticastMessage ¶ added in v2.5.0
func (s *Session) WriteMulticastMessage(req *pool.Message, address *net.UDPAddr, opts ...coapNet.MulticastOption) error
WriteMulticastMessage sends multicast to the remote multicast address. By default it is sent over all network interfaces and all compatible source IP addresses with hop limit 1. Via opts you can specify the network interface, source IP address, and hop limit.
type TransmissionOpt ¶
type TransmissionOpt struct {
// contains filtered or unexported fields
}
TransmissionOpt transmission options.
func WithTransmission ¶
func WithTransmission(transmissionNStart time.Duration, transmissionAcknowledgeTimeout time.Duration, transmissionMaxRetransmit uint32) TransmissionOpt
WithTransmission set options for (re)transmission for Confirmable message-s.