PacketPeerUDP
UDP packet peer.
PacketPeerUDP.swift:14class PacketPeerUDP
UDP packet peer. Can be used to send raw UDP packets as well as Variant
s.
Superclasses
class PacketPeer
Abstraction and base class for packet-based protocols.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
func bind(port: Int32, bindAddress: String, recvBufSize: Int32
) -> GodotError Binds this
PacketPeerUDP
to the specifiedport
andbindAddress
with a buffer sizerecvBufSize
, allowing it to receive incoming packets.func close(
) Closes the
PacketPeerUDP
’s underlying UDP socket.func connectToHost(String, port: Int32
) -> GodotError Calling this method connects this UDP peer to the given
host
/port
pair. UDP is in reality connectionless, so this option only means that incoming packets from different addresses are automatically discarded, and that outgoing packets are always sent to the connected address (future calls tosetDestAddress(host:port:)
are not allowed). This method does not send any data to the remote peer, to do that, useputVar(_:fullObjects:)
orputPacket(buffer:)
as usual. See alsoUDPServer
.func getLocalPort(
) -> Int32 Returns the local port to which this peer is bound.
func getPacketIp(
) -> String Returns the IP of the remote peer that sent the last packet(that was received with
getPacket
orgetVar(allowObjects:)
).func getPacketPort(
) -> Int32 Returns the port of the remote peer that sent the last packet(that was received with
getPacket
orgetVar(allowObjects:)
).func isBound(
) -> Bool Returns whether this
PacketPeerUDP
is bound to an address and can receive packets.func isSocketConnected(
) -> Bool Returns
true
if the UDP socket is open and has been connected to a remote address. SeeconnectToHost(_:port:)
.func joinMulticastGroup(multicastAddress: String, interfaceName: String
) -> GodotError Joins the multicast group specified by
multicastAddress
using the interface identified byinterfaceName
.func leaveMulticastGroup(multicastAddress: String, interfaceName: String
) -> GodotError Removes the interface identified by
interfaceName
from the multicast group specified bymulticastAddress
.func setBroadcastEnabled(Bool
) Enable or disable sending of broadcast packets (e.g.
set_dest_address("255.255.255.255", 4343)
. This option is disabled by default.func setDestAddress(host: String, port: Int32
) -> GodotError Sets the destination address and port for sending packets and variables. A hostname will be resolved using DNS if needed.
func wait(
) -> GodotError Waits for a packet to arrive on the bound address. See
bind(port:bindAddress:recvBufSize:)
.