udp

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package udp 一个非阻塞的 UDP Server 实现

O功能

这是一个用于全部

Index

Constants

This section is empty.

Variables

View Source
var (
	// ServerBindError ...
	ServerBindError = errcode.NewError(baseCode+1, "端口绑定失败")
	// ServerAddrError ...
	ServerAddrError = errcode.NewError(baseCode+2, "IP配置异常")

	// NetConnectError ...
	NetConnectError = errcode.NewError(baseCode+10, "套接字已关闭")

	// SendChannelClosed ...
	SendChannelClosed = errcode.NewError(baseCode+20, "发送通道已关闭")
	// RecvChannelClosed ...
	RecvChannelClosed = errcode.NewError(baseCode+21, "接收通道已关闭")

	// SendDataLenError ...
	SendDataLenError = errcode.NewError(baseCode+30, "发送数据长度异常")
	// SendError ...
	SendError = errcode.NewError(baseCode+31, "发送过程中出现异常")
	// RecvError ...
	RecvError = errcode.NewError(baseCode+32, "数据接收过程中出现异常")
)

Functions

This section is empty.

Types

type Device

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

Device ...

func (*Device) Addr

func (d *Device) Addr() *net.UDPAddr

Addr ...

func (*Device) DisConnect

func (d *Device) DisConnect()

DisConnect ...

func (*Device) IsConnect

func (d *Device) IsConnect() bool

IsConnect ...

func (*Device) SetAddr

func (d *Device) SetAddr(addr *net.UDPAddr)

SetAddr

type UDPData

type UDPData struct {
	RemoteAddr *net.UDPAddr // 发送方地址
	Data       []byte       // 数据
}

UDPData 缓存接收到的UDP数据

type UDPServer

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

UDPServer ...

func NewUDPServer

func NewUDPServer(s *UDPSettingS) (*UDPServer, error)

NewUDPServer 根据UDP配置初始化 UDPServer

func (*UDPServer) Close

func (s *UDPServer) Close() error

Close ...

func (UDPServer) GetErrCh

func (s UDPServer) GetErrCh() <-chan error

GetErrCh ...

func (UDPServer) GetRecvCh

func (s UDPServer) GetRecvCh() <-chan *UDPData

GetRecvCh ...

func (*UDPServer) GetSendCh

func (s *UDPServer) GetSendCh() chan<- *UDPData

GetSendCh ...

type UDPSettingS

type UDPSettingS struct {
	ServerHost       string // 监听的设备通讯
	RecvBufSize      int    // 接收一包数据大小
	RecvChannelSize  int    // 接收通道长度
	SendChannelSize  int    // 发送通道长度
	UseErrorChannel  bool   // 是否使用错误处理通道
	ErrorChannelSize int    // 错误通道缓存

}

UDPSettingS ...

func (*UDPSettingS) String

func (s *UDPSettingS) String() string

String ...

Jump to

Keyboard shortcuts

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