udp

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPacketSize      = 4096
	DefaultPacketQueueSize = 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Obj

type Obj struct {
	log.Logger
	protocol.InterceptorHolder

	WriteTimeout time.Duration
	// contains filtered or unexported fields
}

func New

func New(so protocol.InterceptorHolder, opts ...Opt) (obj *Obj)

func (*Obj) AsBaseConn

func (s *Obj) AsBaseConn() base.Conn

func (*Obj) ClientServe

func (s *Obj) ClientServe(baseCtx context.Context) (err error)

func (*Obj) Close

func (s *Obj) Close() (err error)

func (*Obj) Connect

func (s *Obj) Connect(baseCtx context.Context, config *base.Config) (err error)

Connect to a server endpoint via net.DialUDP()

func (*Obj) Create

func (s *Obj) Create(baseCtx context.Context, network string, config *base.Config) (err error)

Create a server listener via net.ListenUDP()

func (*Obj) IsConnected

func (s *Obj) IsConnected() bool

func (*Obj) Join

func (s *Obj) Join(ctx context.Context, done chan bool)

Join will wait for all internal pumps stopped and close done chan bool

func (*Obj) RawWrite

func (s *Obj) RawWrite(ctx context.Context, data []byte) (n int, err error)

func (*Obj) ReadThrough

func (s *Obj) ReadThrough(data []byte) (n int, err error)

ReadThrough read binary data to a connected *UDPConn (via udp.Obj.Create())

func (*Obj) RemoteAddr

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

func (*Obj) Serve

func (s *Obj) Serve(baseCtx context.Context) (err error)

func (*Obj) Write

func (s *Obj) Write(data *base.UdpPacket)

Write sent udp-packet to a known peer asynchronously

func (*Obj) WriteThrough

func (s *Obj) WriteThrough(data []byte) (n int, err error)

WriteThrough send binary data to a connected *UDPConn (via udp.Obj.Create())

func (*Obj) WriteTo

func (s *Obj) WriteTo(remoteAddr *net.UDPAddr, data []byte)

WriteTo sent udp-packet to a known peer asynchronously. remoteAddr can be nil if sending for a client connected by udp.Create().

type Opt

type Opt func(*Obj)

func WithListenerNumber

func WithListenerNumber(n int) Opt

func WithUDPConn

func WithUDPConn(conn *net.UDPConn, addr *net.UDPAddr) Opt

Jump to

Keyboard shortcuts

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