udp

package
v0.0.0-...-f6b832a Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Udp socket builder

Example (Client1)
c := udp.NewClient(rndzServer, "c1", netip.AddrPort{})
defer c.Close()
l, _ := c.Listen(context.Background())
defer l.Close()
buf := make([]byte, 5)
for {
	l.ReadFrom(buf)
	//    ...
}
Output:

Example (Client2)
c := udp.NewClient(rndzServer, "c2", netip.AddrPort{})
defer c.Close()
conn, _ := c.Connect(context.Background(), "c1")
conn.Write([]byte("hello"))
defer conn.Close()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(localAddr string) (net.PacketConn, error)

raw bind (unconnected udp)

Connect() return a connnected udp, some 3rd package want a unconnected udp.

Types

type Client

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

Udp socket builder

func New

func New(rndzServer, id string, localAddr netip.AddrPort) *Client

set rendezvous server, peer identity, local bind address. if no local address set, choose according server address type(ipv4 or ipv6).

func (*Client) Close

func (c *Client) Close()

stop internal goroutine

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, targetId string) (udpConn *net.UDPConn, err error)

send rendezvous server a request to connect target peer. dial to target peer, return a connected udp

func (*Client) Listen

func (c *Client) Listen(ctx context.Context) (net.PacketConn, error)

keep ping rendezvous server, wait for peer connection request.

when received `Fsync` request from server, attempt to send remote peer a packet this will open the firwall and nat rule for the peer.

Jump to

Keyboard shortcuts

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