multicast

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package multicast provides utilities for network multicast.

Index

Constants

This section is empty.

Variables

View Source
var RecvAddrResolver = &AddrResolver{Addr: "224.0.0.1:1900"}

Functions

func SendAddr

func SendAddr() (*net.UDPAddr, error)

SendAddr returns an address to send multicast UDP package.

func SetRecvAddrIPv4

func SetRecvAddrIPv4(addr string) error

SetRecvAddrIPv4 updates multicast address where to receive packets. This never fail now.

func SetSendAddrIPv4

func SetSendAddrIPv4(addr string) error

SetSendAddrIPv4 updates a UDP address to send multicast packets. This never fail now.

Types

type AddrResolver

type AddrResolver struct {
	Addr string
	// contains filtered or unexported fields
}

type BytesDataProvider

type BytesDataProvider []byte

func (BytesDataProvider) Bytes

func (b BytesDataProvider) Bytes(ifi *net.Interface) []byte

type Conn

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

Conn is multicast connection.

func Listen

func Listen(r *AddrResolver) (*Conn, error)

Listen starts to receiving multicast messages.

func (*Conn) Close

func (mc *Conn) Close() error

Close closes a multicast connection.

func (*Conn) LocalAddr

func (mc *Conn) LocalAddr() net.Addr

LocalAddr returns local address to listen multicast packets.

func (*Conn) ReadPackets

func (mc *Conn) ReadPackets(timeout time.Duration, h PacketHandler) error

ReadPackets reads multicast packets.

func (*Conn) WriteTo

func (mc *Conn) WriteTo(dataProv DataProvider, to net.Addr) (int, error)

WriteTo sends a multicast message to interfaces.

type DataProvider

type DataProvider interface {
	Bytes(*net.Interface) []byte
}

DataProvider provides a body of multicast message to send.

type InterfacesProviderFunc

type InterfacesProviderFunc func() []net.Interface
var InterfacesProvider InterfacesProviderFunc

InterfacesProvider specify a function to list all interfaces to multicast. If no provider are given, all possible interfaces will be used.

type PacketHandler

type PacketHandler func(net.Addr, []byte) error

Jump to

Keyboard shortcuts

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