Documentation ¶
Overview ¶
Package ENetConnection provides methods for working with ENetConnection object instances.
Index ¶
- type Advanced
- type Any
- type CompressionMode
- type EventType
- type HostStatistic
- type Instance
- func (self Instance) AsENetConnection() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) BandwidthLimit()
- func (self Instance) Broadcast(channel int, packet []byte, flags int)
- func (self Instance) ChannelLimit(limit int)
- func (self Instance) Compress(mode gdclass.ENetConnectionCompressionMode)
- func (self Instance) ConnectToHost(address string, port int) [1]gdclass.ENetPacketPeer
- func (self Instance) CreateHost() error
- func (self Instance) CreateHostBound(bind_address string, bind_port int) error
- func (self Instance) Destroy()
- func (self Instance) DtlsClientSetup(hostname string) error
- func (self Instance) DtlsServerSetup(server_options [1]gdclass.TLSOptions) error
- func (self Instance) Flush()
- func (self Instance) GetLocalPort() int
- func (self Instance) GetMaxChannels() int
- func (self Instance) GetPeers() [][1]gdclass.ENetPacketPeer
- func (self Instance) PopStatistic(statistic gdclass.ENetConnectionHostStatistic) Float.X
- func (self Instance) RefuseNewConnections(refuse bool)
- func (self Instance) Service() []any
- func (self Instance) SocketSend(destination_address string, destination_port int, packet []byte)
- func (self *Instance) UnsafePointer() unsafe.Pointer
- func (self Instance) Virtual(name string) reflect.Value
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 CompressionMode ¶
type CompressionMode = gdclass.ENetConnectionCompressionMode //gd:ENetConnection.CompressionMode
const ( /*No compression. This uses the most bandwidth, but has the upside of requiring the fewest CPU resources. This option may also be used to make network debugging using tools like Wireshark easier.*/ CompressNone CompressionMode = 0 /*ENet's built-in range encoding. Works well on small packets, but is not the most efficient algorithm on packets larger than 4 KB.*/ CompressRangeCoder CompressionMode = 1 /*[url=https://fastlz.org/]FastLZ[/url] compression. This option uses less CPU resources compared to [constant COMPRESS_ZLIB], at the expense of using more bandwidth.*/ CompressFastlz CompressionMode = 2 /*[url=https://www.zlib.net/]Zlib[/url] compression. This option uses less bandwidth compared to [constant COMPRESS_FASTLZ], at the expense of using more CPU resources.*/ CompressZlib CompressionMode = 3 /*[url=https://facebook.github.io/zstd/]Zstandard[/url] compression. Note that this algorithm is not very efficient on packets smaller than 4 KB. Therefore, it's recommended to use other compression algorithms in most cases.*/ CompressZstd CompressionMode = 4 )
type EventType ¶
type EventType = gdclass.ENetConnectionEventType //gd:ENetConnection.EventType
const ( /*An error occurred during [method service]. You will likely need to [method destroy] the host and recreate it.*/ EventError EventType = -1 /*No event occurred within the specified time limit.*/ EventNone EventType = 0 /*A connection request initiated by enet_host_connect has completed. The array will contain the peer which successfully connected.*/ EventConnect EventType = 1 /*A peer has disconnected. This event is generated on a successful completion of a disconnect initiated by [method ENetPacketPeer.peer_disconnect], if a peer has timed out, or if a connection request initialized by [method connect_to_host] has timed out. The array will contain the peer which disconnected. The data field contains user supplied data describing the disconnection, or 0, if none is available.*/ EventDisconnect EventType = 2 /*A packet has been received from a peer. The array will contain the peer which sent the packet and the channel number upon which the packet was received. The received packet will be queued to the associated [ENetPacketPeer].*/ EventReceive EventType = 3 )
type HostStatistic ¶
type HostStatistic = gdclass.ENetConnectionHostStatistic //gd:ENetConnection.HostStatistic
const ( /*Total data sent.*/ HostTotalSentData HostStatistic = 0 /*Total UDP packets sent.*/ HostTotalSentPackets HostStatistic = 1 /*Total data received.*/ HostTotalReceivedData HostStatistic = 2 /*Total UDP packets received.*/ HostTotalReceivedPackets HostStatistic = 3 )
type Instance ¶
type Instance [1]gdclass.ENetConnection
ENet's purpose is to provide a relatively thin, simple and robust network communication layer on top of UDP (User Datagram Protocol).
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsENetConnection ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) BandwidthLimit ¶
func (self Instance) BandwidthLimit()
Adjusts the bandwidth limits of a host.
func (Instance) Broadcast ¶
Queues a [param packet] to be sent to all peers associated with the host over the specified [param channel]. See [ENetPacketPeer] [code]FLAG_*[/code] constants for available packet flags.
func (Instance) ChannelLimit ¶
Limits the maximum allowed channels of future incoming connections.
func (Instance) Compress ¶
func (self Instance) Compress(mode gdclass.ENetConnectionCompressionMode)
Sets the compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all. [b]Note:[/b] Most games' network design involve sending many small packets frequently (smaller than 4 KB each). If in doubt, it is recommended to keep the default compression algorithm as it works best on these small packets. [b]Note:[/b] The compression mode must be set to the same value on both the server and all its clients. Clients will fail to connect if the compression mode set on the client differs from the one set on the server.
func (Instance) ConnectToHost ¶
func (self Instance) ConnectToHost(address string, port int) [1]gdclass.ENetPacketPeer
Initiates a connection to a foreign [param address] using the specified [param port] and allocating the requested [param channels]. Optional [param data] can be passed during connection in the form of a 32 bit integer. [b]Note:[/b] You must call either [method create_host] or [method create_host_bound] on both ends before calling this method.
func (Instance) CreateHost ¶
Creates an ENetHost that allows up to [param max_peers] connected peers, each allocating up to [param max_channels] channels, optionally limiting bandwidth to [param in_bandwidth] and [param out_bandwidth] (if greater than zero). This method binds a random available dynamic UDP port on the host machine at the [i]unspecified[/i] address. Use [method create_host_bound] to specify the address and port. [b]Note:[/b] It is necessary to create a host in both client and server in order to establish a connection.
func (Instance) CreateHostBound ¶
Creates an ENetHost bound to the given [param bind_address] and [param bind_port] that allows up to [param max_peers] connected peers, each allocating up to [param max_channels] channels, optionally limiting bandwidth to [param in_bandwidth] and [param out_bandwidth] (if greater than zero). [b]Note:[/b] It is necessary to create a host in both client and server in order to establish a connection.
func (Instance) Destroy ¶
func (self Instance) Destroy()
Destroys the host and all resources associated with it.
func (Instance) DtlsClientSetup ¶
Configure this ENetHost to use the custom Godot extension allowing DTLS encryption for ENet clients. Call this before [method connect_to_host] to have ENet connect using DTLS validating the server certificate against [param hostname]. You can pass the optional [param client_options] parameter to customize the trusted certification authorities, or disable the common name verification. See [method TLSOptions.client] and [method TLSOptions.client_unsafe].
func (Instance) DtlsServerSetup ¶
func (self Instance) DtlsServerSetup(server_options [1]gdclass.TLSOptions) error
Configure this ENetHost to use the custom Godot extension allowing DTLS encryption for ENet servers. Call this right after [method create_host_bound] to have ENet expect peers to connect using DTLS. See [method TLSOptions.server].
func (Instance) Flush ¶
func (self Instance) Flush()
Sends any queued packets on the host specified to its designated peers.
func (Instance) GetLocalPort ¶
Returns the local port to which this peer is bound.
func (Instance) GetMaxChannels ¶
Returns the maximum number of channels allowed for connected peers.
func (Instance) GetPeers ¶
func (self Instance) GetPeers() [][1]gdclass.ENetPacketPeer
Returns the list of peers associated with this host. [b]Note:[/b] This list might include some peers that are not fully connected or are still being disconnected.
func (Instance) PopStatistic ¶
func (self Instance) PopStatistic(statistic gdclass.ENetConnectionHostStatistic) Float.X
Returns and resets host statistics. See [enum HostStatistic] for more info.
func (Instance) RefuseNewConnections ¶
Configures the DTLS server to automatically drop new connections. [b]Note:[/b] This method is only relevant after calling [method dtls_server_setup].
func (Instance) Service ¶
Waits for events on this connection and shuttles packets between the host and its peers, with the given [param timeout] (in milliseconds). The returned [Array] will have 4 elements. An [enum EventType], the [ENetPacketPeer] which generated the event, the event associated data (if any), the event associated channel (if any). If the generated event is [constant EVENT_RECEIVE], the received packet will be queued to the associated [ENetPacketPeer]. Call this function regularly to handle connections, disconnections, and to receive new packets. [b]Note:[/b] This method must be called on both ends involved in the event (sending and receiving hosts).
func (Instance) SocketSend ¶
Sends a [param packet] toward a destination from the address and port currently bound by this ENetConnection instance. This is useful as it serves to establish entries in NAT routing tables on all devices between this bound instance and the public facing internet, allowing a prospective client's connection packets to be routed backward through the NAT device(s) between the public internet and this host. This requires forward knowledge of a prospective client's address and communication port as seen by the public internet - after any NAT devices have handled their connection request. This information can be obtained by a [url=https://en.wikipedia.org/wiki/STUN]STUN[/url] service, and must be handed off to your host by an entity that is not the prospective client. This will never work for a client behind a Symmetric NAT due to the nature of the Symmetric NAT routing algorithm, as their IP and Port cannot be known beforehand.