udpx

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(ctx contextx.Context, ops ...func(opt *Option)) error

func PutPackage

func PutPackage(pkg *Package)

func SendBinaryMsg

func SendBinaryMsg(rAddr *net.UDPAddr, data []byte)

func SendTextMsg

func SendTextMsg(rAddr *net.UDPAddr, data []byte)

Types

type MsgType

type MsgType int8
const (
	TextMessage   MsgType = 1
	BinaryMessage MsgType = 2
)

type Option

type Option struct {
	//ListenIp       string // 监听IP
	//Port           int    // 监听端口
	LAddr          *net.UDPAddr
	WriteTimeout   time.Duration
	MaxPkgSize     int32
	OnMsgHandle    func(addr *net.UDPAddr, data []byte)
	OnBinaryHandle func(addr *net.UDPAddr, data []byte)
}

type Package

type Package struct {
	Type    MsgType
	Payload []byte
}

func GetPackage

func GetPackage() *Package

func (*Package) Marshal

func (p *Package) Marshal() []byte

func (*Package) Unmarshal

func (p *Package) Unmarshal(body []byte)

Jump to

Keyboard shortcuts

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