PacketPeerUDP

package
v0.0.0-...-01268d7 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package PacketPeerUDP provides methods for working with PacketPeerUDP object instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsPacketPeerUDP() Instance
}

type Instance

type Instance [1]gdclass.PacketPeerUDP

UDP packet peer. Can be used to send raw UDP packets as well as [Variant]s. [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsPacketPeer

func (self Instance) AsPacketPeer() PacketPeer.Instance

func (Instance) AsPacketPeerUDP

func (self Instance) AsPacketPeerUDP() Instance

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) Bind

func (self Instance) Bind(port int) error

Binds this [PacketPeerUDP] to the specified [param port] and [param bind_address] with a buffer size [param recv_buf_size], allowing it to receive incoming packets. If [param bind_address] is set to [code]"*"[/code] (default), the peer will be bound on all available addresses (both IPv4 and IPv6). If [param bind_address] is set to [code]"0.0.0.0"[/code] (for IPv4) or [code]"::"[/code] (for IPv6), the peer will be bound to all available addresses matching that IP type. If [param bind_address] is set to any valid address (e.g. [code]"192.168.1.101"[/code], [code]"::1"[/code], etc.), the peer will only be bound to the interface with that address (or fail if no interface with the given address exists).

func (Instance) Close

func (self Instance) Close()

Closes the [PacketPeerUDP]'s underlying UDP socket.

func (Instance) ConnectToHost

func (self Instance) ConnectToHost(host string, port int) error

Calling this method connects this UDP peer to the given [param host]/[param 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 to [method set_dest_address] are not allowed). This method does not send any data to the remote peer, to do that, use [method PacketPeer.put_var] or [method PacketPeer.put_packet] as usual. See also [UDPServer]. [b]Note:[/b] Connecting to the remote peer does not help to protect from malicious attacks like IP spoofing, etc. Think about using an encryption technique like TLS or DTLS if you feel like your application is transferring sensitive information.

func (Instance) GetLocalPort

func (self Instance) GetLocalPort() int

Returns the local port to which this peer is bound.

func (Instance) GetPacketIp

func (self Instance) GetPacketIp() string

Returns the IP of the remote peer that sent the last packet(that was received with [method PacketPeer.get_packet] or [method PacketPeer.get_var]).

func (Instance) GetPacketPort

func (self Instance) GetPacketPort() int

Returns the port of the remote peer that sent the last packet(that was received with [method PacketPeer.get_packet] or [method PacketPeer.get_var]).

func (Instance) IsBound

func (self Instance) IsBound() bool

Returns whether this [PacketPeerUDP] is bound to an address and can receive packets.

func (Instance) IsSocketConnected

func (self Instance) IsSocketConnected() bool

Returns [code]true[/code] if the UDP socket is open and has been connected to a remote address. See [method connect_to_host].

func (Instance) JoinMulticastGroup

func (self Instance) JoinMulticastGroup(multicast_address string, interface_name string) error

Joins the multicast group specified by [param multicast_address] using the interface identified by [param interface_name]. You can join the same multicast group with multiple interfaces. Use [method IP.get_local_interfaces] to know which are available. [b]Note:[/b] Some Android devices might require the [code]CHANGE_WIFI_MULTICAST_STATE[/code] permission for multicast to work.

func (Instance) LeaveMulticastGroup

func (self Instance) LeaveMulticastGroup(multicast_address string, interface_name string) error

Removes the interface identified by [param interface_name] from the multicast group specified by [param multicast_address].

func (Instance) SetBroadcastEnabled

func (self Instance) SetBroadcastEnabled(enabled bool)

Enable or disable sending of broadcast packets (e.g. [code]set_dest_address("255.255.255.255", 4343)[/code]. This option is disabled by default. [b]Note:[/b] Some Android devices might require the [code]CHANGE_WIFI_MULTICAST_STATE[/code] permission and this option to be enabled to receive broadcast packets too.

func (Instance) SetDestAddress

func (self Instance) SetDestAddress(host string, port int) error

Sets the destination address and port for sending packets and variables. A hostname will be resolved using DNS if needed. [b]Note:[/b] [method set_broadcast_enabled] must be enabled before sending packets to a broadcast address (e.g. [code]255.255.255.255[/code]).

func (*Instance) UnsafePointer

func (self *Instance) UnsafePointer() unsafe.Pointer

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

func (Instance) Wait

func (self Instance) Wait() error

Waits for a packet to arrive on the bound address. See [method bind]. [b]Note:[/b] [method wait] can't be interrupted once it has been called. This can be worked around by allowing the other party to send a specific "death pill" packet like this: [codeblocks] [gdscript] socket = PacketPeerUDP.new() # Server socket.set_dest_address("127.0.0.1", 789) socket.put_packet("Time to stop".to_ascii_buffer())

# Client while socket.wait() == OK:

var data = socket.get_packet().get_string_from_ascii()
if data == "Time to stop":
    return

[/gdscript] [csharp] var socket = new PacketPeerUdp(); // Server socket.SetDestAddress("127.0.0.1", 789); socket.PutPacket("Time to stop".ToAsciiBuffer());

// Client while (socket.Wait() == OK)

{
    string data = socket.GetPacket().GetStringFromASCII();
    if (data == "Time to stop")
    {
        return;
    }
}

[/csharp] [/codeblocks]

Jump to

Keyboard shortcuts

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