udp

package
v0.0.0-...-68bdf18 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Opening = iota
	Closed
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MsgHandler

type MsgHandler func(*Server, *net.UDPAddr, proto.Message)

遇到某消息ID的回调函数类型

type PacketFactory

type PacketFactory func(uint) proto.Message

消息ID与消息PB的映射函数类型

type SendTask

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

type Server

type Server struct {
	Name string
	Ip   string
	Port int

	SubscribeBook *SubscribeList //被订阅列表
	// contains filtered or unexported fields
}

func CreateServer

func CreateServer(serviceName string, ip string, port int) (*Server, error)

创建一个UDP服务

func (*Server) Close

func (server *Server) Close()

func (*Server) RegHandler

func (server *Server) RegHandler(cmdId uint, handler MsgHandler)

设置消息ID对应的回调

func (*Server) Send

func (server *Server) Send(cmdId uint, pb proto.Message, addr *net.UDPAddr) bool

发消息

func (*Server) SetFactory

func (server *Server) SetFactory(f PacketFactory)

设置消息ID与消息PB的映射函数

func (*Server) Start

func (server *Server) Start() error

启动服务

type SubscribeList

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

被订阅列表结构

func CreateSubscribeList

func CreateSubscribeList() *SubscribeList

创建订阅列表

func (*SubscribeList) GetSubscribers

func (sl *SubscribeList) GetSubscribers(infoKey interface{}, del bool) []*net.UDPAddr

获取订阅了key的连接们

func (*SubscribeList) Subscribe

func (sl *SubscribeList) Subscribe(infoKey interface{}, addr *net.UDPAddr)

key被某udp地址所订阅

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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