enet

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT, BSD-2-Clause Imports: 7 Imported by: 0

README

Forked from sauerbraten/waiter with some modifications.

Documentation

Index

Constants

View Source
const (
	EventTypeConnect    = C.ENET_EVENT_TYPE_CONNECT
	EventTypeDisconnect = C.ENET_EVENT_TYPE_DISCONNECT
	EventTypeReceive    = C.ENET_EVENT_TYPE_RECEIVE
)
View Source
const (
	PacketFlagNone               = 0
	PacketFlagReliable           = (1 << 0)
	PacketFlagUnsequenced        = (1 << 1)
	PacketFlagNoAllocate         = (1 << 2)
	PacketFlagUnreliableFragment = (1 << 3)
	PacketFlagSent               = (1 << 8)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ENetSocketType

type ENetSocketType int

type Event

type Event struct {
	Type      EventType
	Peer      *Peer
	ChannelID uint8
	Data      uint32
	Packet    *Packet
}

type EventType

type EventType uint

type Host

type Host struct {
	Mutex deadlock.Mutex
	// contains filtered or unexported fields
}

func NewConnectHost

func NewConnectHost(laddr string, lport int) (*Host, error)

func NewHost

func NewHost(laddr string, lport int) (*Host, error)

func (*Host) Disconnect

func (h *Host) Disconnect(p *Peer, reason ID)

func (*Host) Service

func (h *Host) Service() <-chan Event

func (*Host) Shutdown

func (h *Host) Shutdown()

type ID

type ID uint32
const (
	None ID = iota
	EOP
	LocalMode // LOCAL
	Kick
	MessageError // MSGERR
	IPBanned     // IPBAN
	PrivateMode  // PRIVATE
	Full         // MAXCLIENTS
	Timeout
	Overflow
	WrongPassword // PASSWORD
)

func (ID) String

func (dr ID) String() string

type Packet

type Packet struct {
	Flags uint32 // bitwise-or of ENetPacketFlag constants
	Data  []byte // allocated data for packet
}

type Peer

type Peer struct {
	Address *net.UDPAddr
	State   PeerState
	CPeer   *C.ENetPeer

	// Messages for which we have yet to receive ACKs
	Pending []PendingPacket
	Queued  []QueuedPacket
	Mutex   deadlock.Mutex
}

func (*Peer) CheckACKs

func (p *Peer) CheckACKs()

func (*Peer) Send

func (p *Peer) Send(channel uint8, payload []byte) <-chan error

type PeerState

type PeerState uint

type PendingPacket

type PendingPacket struct {
	Sequence uint16
	Error    chan error
}

type QueuedPacket

type QueuedPacket struct {
	Channel uint8
	Data    []byte
	Error   chan error
}

type Socket

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

func NewConnectSocket

func NewConnectSocket(host string, port int) (*Socket, error)

func NewDatagramSocket

func NewDatagramSocket(port int) (*Socket, error)

func (*Socket) DestroySocket

func (sock *Socket) DestroySocket()

func (*Socket) Receive

func (sock *Socket) Receive() (string, int)

func (*Socket) Send

func (sock *Socket) Send(payload []byte)

func (*Socket) SendDatagram

func (sock *Socket) SendDatagram(address C.ENetAddress, data []byte)

func (*Socket) SendString

func (sock *Socket) SendString(str string) error

func (*Socket) Service

func (sock *Socket) Service() <-chan SocketMessage

type SocketMessage

type SocketMessage struct {
	Address C.ENetAddress
	Data    []byte
}

Jump to

Keyboard shortcuts

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