mirror of
https://github.com/codecat/go-enet.git
synced 2025-12-08 05:59:47 +00:00
Added broadcast functions
This commit is contained in:
parent
bd2e8a9be1
commit
378f679fd1
1 changed files with 28 additions and 0 deletions
28
host.go
28
host.go
|
|
@ -14,6 +14,9 @@ type Host interface {
|
||||||
Connect(addr Address, channelCount int, data uint32) (Peer, error)
|
Connect(addr Address, channelCount int, data uint32) (Peer, error)
|
||||||
|
|
||||||
CompressWithRangeCoder() error
|
CompressWithRangeCoder() error
|
||||||
|
BroadcastBytes(data []byte, channel uint8, flags PacketFlags) error
|
||||||
|
BroadcastPacket(packet Packet, channel uint8) error
|
||||||
|
BroadcastString(str string, channel uint8, flags PacketFlags) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type enetHost struct {
|
type enetHost struct {
|
||||||
|
|
@ -86,3 +89,28 @@ func NewHost(addr Address, peerCount, channelLimit uint64, incomingBandwidth, ou
|
||||||
cHost: host,
|
cHost: host,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (host *enetHost) BroadcastBytes(data []byte, channel uint8, flags PacketFlags) error {
|
||||||
|
packet, err := NewPacket(data, flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return host.BroadcastPacket(packet, channel)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (host *enetHost) BroadcastPacket(packet Packet, channel uint8) error {
|
||||||
|
C.enet_host_broadcast(
|
||||||
|
host.cHost,
|
||||||
|
(C.enet_uint8)(channel),
|
||||||
|
packet.(enetPacket).cPacket,
|
||||||
|
)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (host *enetHost) BroadcastString(str string, channel uint8, flags PacketFlags) error {
|
||||||
|
packet, err := NewPacket([]byte(str), flags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return host.BroadcastPacket(packet, channel)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue