ioer

package module
v0.0.0-...-d38310f Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2021 License: MIT Imports: 10 Imported by: 0

README

ioer:UDP端口复用


当使用

net.DialUDP("udp",&net.UDPAddr{IP: nil,Port: 19986},&net.UDPAddr{IP: net.ParseIP("3.3.3.3"),Port: 19986})

后,本地的19986端口就不能再被使用了。但是理论上只要四元组中存在不同,就是可以建立连接的。

ioer实际是通过net.ListenUDP来实现的,发送数据时使用conn.WriteTo,接收数据时通过raddr将数据路由到对应的ioer.Conn

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ListenersList map[int64]*Listener // 记录全局Listener

全局变量

Functions

This section is empty.

Types

type Conn

type Conn struct {
	Lconn *net.UDPConn // unconnected net.UCPConn
	// contains filtered or unexported fields
}

Conn 表示一个链接

func Dial

func Dial(laddr, raddr *net.UDPAddr) (*Conn, error)

Dial

func (*Conn) Close

func (c *Conn) Close() error

Close 关闭

func (*Conn) Delete

func (cs *Conn) Delete(c *Conn)

Delete 删除并关闭连接

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

Read 读取数据; 确保b的长度足够大(65536), 否则会丢失部分数据

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

Write 发送数据

type Conns

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

func (*Conns) Add

func (cs *Conns) Add(c *Conn)

Add 增加宏端口中的连接

func (*Conns) Dial

func (cs *Conns) Dial(laddr, raddr *net.UDPAddr) (*Conn, error)

Dial 增加宏端口中连接,并返回这个连接

func (*Conns) Read

func (cs *Conns) Read() (int, error)

Read 读取

func (*Conns) Write

func (cs *Conns) Write() (int, error)

Write 写入

func (*Conns) WriteTo

func (cs *Conns) WriteTo() (int, error)

type Listener

type Listener struct {
	sync.Mutex // 锁, 凡是connList写的地方需要上锁
	// contains filtered or unexported fields
}

func Listen

func Listen(laddr *net.UDPAddr) (*Listener, error)

Listen 监听本地地址, 不会阻塞

func (*Listener) Accept

func (l *Listener) Accept() *Conn

Accept 结束请求, 类似于TCP的Accept

如果Listener.run中没有写权鉴,则会接收所有连接请求

func (*Listener) Close

func (l *Listener) Close() error

Close 会关闭所有链接

func (*Listener) Delete

func (l *Listener) Delete(conn *Conn)

Delete 将Conn中此Listener中删除

可以依据删除

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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