server

package
v3.5.7 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 20 Imported by: 8 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = func() Config {
	opts := Config{
		Common: config.NewCommon[*udpClient.Conn](),
		CreateInactivityMonitor: func() udpClient.InactivityMonitor {
			timeout := time.Second * 16
			onInactive := func(cc *udpClient.Conn) {
				_ = cc.Close()
			}
			return inactivity.New(timeout, onInactive)
		},
		RequestMonitor: func(*udpClient.Conn, *pool.Message) (bool, error) {
			return false, nil
		},
		OnNewConn: func(*udpClient.Conn) {

		},
		TransmissionNStart:             1,
		TransmissionAcknowledgeTimeout: time.Second * 2,
		TransmissionMaxRetransmit:      4,
		HandshakeTimeout:               30 * time.Second,
		GetMID:                         message.GetMID,
		MTU:                            udpClient.DefaultMTU,
	}
	opts.Handler = func(w *responsewriter.ResponseWriter[*udpClient.Conn], _ *pool.Message) {
		if err := w.SetResponse(codes.NotFound, message.TextPlain, nil); err != nil {
			opts.Errors(fmt.Errorf("dtls server: cannot set response: %w", err))
		}
	}
	return opts
}()

Functions

This section is empty.

Types

type Config

type Config struct {
	config.Common[*udpClient.Conn]
	CreateInactivityMonitor        func() udpClient.InactivityMonitor
	GetMID                         GetMIDFunc
	Handler                        HandlerFunc
	OnNewConn                      OnNewConnFunc
	RequestMonitor                 udpClient.RequestMonitorFunc
	TransmissionNStart             uint32
	TransmissionAcknowledgeTimeout time.Duration
	TransmissionMaxRetransmit      uint32
	HandshakeTimeout               time.Duration
	MTU                            uint16
}

type ErrorFunc

type ErrorFunc = func(error)

type EventFunc

type EventFunc = func()

type GetMIDFunc

type GetMIDFunc = func() int32

type HandlerFunc

type HandlerFunc = func(*responsewriter.ResponseWriter[*udpClient.Conn], *pool.Message)

The HandlerFunc type is an adapter to allow the use of ordinary functions as COAP handlers.

type Listener

type Listener interface {
	Close() error
	AcceptWithContext(ctx context.Context) (net.Conn, error)
}

Listener defined used by coap

type OnNewConnFunc

type OnNewConnFunc = func(*udpClient.Conn)

OnNewConnFunc is the callback for new connections.

type Option

type Option interface {
	DTLSServerApply(cfg *Config)
}

A Option sets options such as credentials, codec and keepalive parameters, etc.

type Server

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

func New

func New(opt ...Option) *Server

func (*Server) Serve

func (s *Server) Serve(l Listener) error

func (*Server) Stop

func (s *Server) Stop()

Stop stops server without wait of ends Serve function.

type Session

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

func NewSession

func NewSession(
	ctx context.Context,
	connection *coapNet.Conn,
	maxMessageSize uint32,
	mtu uint16,
	closeSocket bool,
) *Session

func (*Session) AddOnClose

func (s *Session) AddOnClose(f EventFunc)

func (*Session) Close

func (s *Session) Close() error

func (*Session) Context

func (s *Session) Context() context.Context

func (*Session) Done

func (s *Session) Done() <-chan struct{}

Done signalizes that connection is not more processed.

func (*Session) LocalAddr

func (s *Session) LocalAddr() net.Addr

func (*Session) MaxMessageSize

func (s *Session) MaxMessageSize() uint32

func (*Session) NetConn

func (s *Session) NetConn() net.Conn

NetConn returns the underlying connection that is wrapped by s. The Conn returned is shared by all invocations of NetConn, so do not modify it.

func (*Session) RemoteAddr

func (s *Session) RemoteAddr() net.Addr

func (*Session) Run

func (s *Session) Run(cc *client.Conn) (err error)

Run reads and processes requests from a connection, until the connection is closed.

func (*Session) SetContextValue

func (s *Session) SetContextValue(key interface{}, val interface{})

SetContextValue stores the value associated with key to context of connection.

func (*Session) WriteMessage

func (s *Session) WriteMessage(req *pool.Message) error

func (*Session) WriteMulticastMessage

func (s *Session) WriteMulticastMessage(*pool.Message, *net.UDPAddr, ...coapNet.MulticastOption) error

WriteMulticastMessage sends multicast to the remote multicast address. Currently it is not implemented - is just satisfy golang udp/client/Session interface.

Jump to

Keyboard shortcuts

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