Inheritance #
- AudioServer
- CameraServer
- ClassDB
- DisplayServer
- EditorFileSystemDirectory
- EditorInterface
- EditorPaths
- EditorSelection
- EditorUndoRedoManager
- EditorVCSInterface
- Engine
- EngineDebugger
- FramebufferCacheRD
- GDExtensionManager
- Geometry2D
- Geometry3D
- IP
- Input
- InputMap
- JNISingleton
- JSONRPC
- JavaClassWrapper
- JavaScriptBridge
- MainLoop (1)
- Marshalls
- MovieWriter
- NativeMenu
- NavigationMeshGenerator
- NavigationServer2D
- NavigationServer3D
- Node (21)
- OS
- OpenXRExtensionWrapperExtension
- OpenXRInteractionProfileMetadata
- Performance
- PhysicsDirectBodyState2D (1)
- PhysicsDirectBodyState3D (1)
- PhysicsDirectSpaceState2D (1)
- PhysicsDirectSpaceState3D (1)
- PhysicsServer2D (1)
- PhysicsServer2DManager
- PhysicsServer3D (1)
- PhysicsServer3DManager
- PhysicsServer3DRendering
ServerHandler
- ProjectSettings
- RefCounted (121)
- RenderData (2)
- RenderSceneData (2)
- RenderingDevice
- RenderingServer
- ResourceLoader
- ResourceSaver
- ResourceUID
- ScriptLanguage (1)
- ShaderIncludeDB
- TextServerManager
- ThemeDB
- TileData
- Time
- TranslationServer
- TreeItem
- UndoRedo
- UniformSetCacheRD
- WorkerThreadPool
- XRServer
- XRVRS
- AESContext
- AStar2D
- AStar3D
- AStarGrid2D
- AudioEffectInstance (1)
- AudioSample
- AudioSamplePlayback
- AudioStreamPlayback (5)
- CameraFeed
- CharFXTransform
- ConfigFile
- Crypto
- DTLSServer
- DirAccess
- ENetConnection
- EditorContextMenuPlugin
- EditorDebuggerPlugin
- EditorDebuggerSession
- EditorExportPlatform (6)
- EditorExportPlugin
- EditorExportPreset
- EditorFeatureProfile
- EditorFileSystemImportFormatSupportQuery
- EditorInspectorPlugin
- EditorResourceConversionPlugin
- EditorResourcePreviewGenerator
- EditorResourceTooltipPlugin
- EditorSceneFormatImporter (4)
- EditorScenePostImport
- EditorScenePostImportPlugin
- EditorScript
- EditorTranslationParserPlugin
- EncodedObjectAsID
- EngineProfiler
- Expression
- FileAccess
- GLTFObjectModelProperty
- HMACContext
- HTTPClient
- HashingContext
- ImageFormatLoader (1)
- JavaClass
- JavaObject
- JavaScriptObject
- KinematicCollision2D
- KinematicCollision3D
- Lightmapper (1)
- MeshConvexDecompositionSettings
- MeshDataTool
- MultiplayerAPI (2)
- Mutex
- NavigationPathQueryParameters2D
- NavigationPathQueryParameters3D
- NavigationPathQueryResult2D
- NavigationPathQueryResult3D
- Node3DGizmo (1)
- OggPacketSequencePlayback
- OpenXRAPIExtension
- PCKPacker
- PackedDataContainerRef
- PacketPeer (8)
- PhysicsPointQueryParameters2D
- PhysicsPointQueryParameters3D
- PhysicsRayQueryParameters2D
- PhysicsRayQueryParameters3D
- PhysicsShapeQueryParameters2D
- PhysicsShapeQueryParameters3D
- PhysicsTestMotionParameters2D
- PhysicsTestMotionParameters3D
- PhysicsTestMotionResult2D
- PhysicsTestMotionResult3D
- RDAttachmentFormat
- RDFramebufferPass
- RDPipelineColorBlendState
- RDPipelineColorBlendStateAttachment
- RDPipelineDepthStencilState
- RDPipelineMultisampleState
- RDPipelineRasterizationState
- RDPipelineSpecializationConstant
- RDSamplerState
- RDShaderSource
- RDTextureFormat
- RDTextureView
- RDUniform
- RDVertexAttribute
- RandomNumberGenerator
- RegEx
- RegExMatch
- RenderSceneBuffers (2)
- RenderSceneBuffersConfiguration
- Resource (103)
- ResourceFormatLoader
- ResourceFormatSaver
- ResourceImporter (16)
- SceneState
- SceneTreeTimer
- Semaphore
- SkinReference
- StreamPeer (5)
- SurfaceTool
- TCPServer
- TLSOptions
- TextLine
- TextParagraph
- TextServer (1)
- Thread
- TranslationDomain
- TriangleMesh
- Tween
- Tweener (5)
- UDPServer
- UPNP
- UPNPDevice
- WeakRef
- WebRTCPeerConnection (1)
- XMLParser
- XRInterface (4)
- XRPose
- XRTracker (2)
- ZIPPacker
- ZIPReader
Table of contents
-
func bandwidth_limit(out_bandwidth: int = 0) -> void -
func broadcast(flags: int) -> void -
func channel_limit(limit: int) -> void -
func compress(mode: int enumENetConnection.CompressionMode) -> void -
func connect_to_host(data: int = 0) -> ENetPacketPeer -
func create_host(out_bandwidth: int = 0) -> intError -
func create_host_bound(out_bandwidth: int = 0) -> intError -
func destroy() -> void -
func dtls_client_setup(client_options: TLSOptions = null) -> intError -
func dtls_server_setup(server_options: TLSOptions) -> intError -
func flush() -> void -
const func get_local_port() -> int -
const func get_max_channels() -> int -
func get_peers() -> ENetPacketPeer[] -
func pop_statistic(statistic: int enumENetConnection.HostStatistic) -> float -
func refuse_new_connections(refuse: bool) -> void -
func service(timeout: int = 0) -> Array -
func socket_send(packet: PackedByteArray) -> void -
const COMPRESS_NONE = 0 enum CompressionMode -
const COMPRESS_RANGE_CODER = 1 enum CompressionMode -
const COMPRESS_FASTLZ = 2 enum CompressionMode -
const COMPRESS_ZLIB = 3 enum CompressionMode -
const COMPRESS_ZSTD = 4 enum CompressionMode -
const EVENT_ERROR = -1 enum EventType -
const EVENT_NONE = 0 enum EventType -
const EVENT_CONNECT = 1 enum EventType -
const EVENT_DISCONNECT = 2 enum EventType -
const EVENT_RECEIVE = 3 enum EventType -
const HOST_TOTAL_SENT_DATA = 0 enum HostStatistic -
const HOST_TOTAL_SENT_PACKETS = 1 enum HostStatistic -
const HOST_TOTAL_RECEIVED_DATA = 2 enum HostStatistic -
const HOST_TOTAL_RECEIVED_PACKETS = 3 enum HostStatistic -
enum CompressionMode -
enum EventType -
enum HostStatistic
ENetConnection #
is_refcounted, is_instantiable, core, not_builtin_classes
A wrapper class for an ENetHost.
ENet's purpose is to provide a relatively thin, simple and robust network communication layer on top of UDP (User Datagram Protocol).
Members #
Methods #
func bandwidth_limit(out_bandwidth: int = 0) -> void#
Adjusts the bandwidth limits of a host.
func broadcast(flags: int) -> void#
Queues a packet to be sent to all peers associated with the host over the specified channel. See ENetPacketPeer FLAG_* constants for available packet flags.
func channel_limit(limit: int) -> void#
Limits the maximum allowed channels of future incoming connections.
func compress(mode: int enumENetConnection.CompressionMode) -> void#
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.
Note: 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.
Note: 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 connect_to_host(data: int = 0) -> ENetPacketPeer#
Initiates a connection to a foreign address using the specified port and allocating the requested channels. Optional data can be passed during connection in the form of a 32 bit integer.
Note: You must call either create_host or create_host_bound on both ends before calling this method.
func create_host(out_bandwidth: int = 0) -> intError#
Creates an ENetHost that allows up to max_peers connected peers, each allocating up to max_channels channels, optionally limiting bandwidth to in_bandwidth and out_bandwidth (if greater than zero).
This method binds a random available dynamic UDP port on the host machine at the unspecified address. Use create_host_bound to specify the address and port.
Note: It is necessary to create a host in both client and server in order to establish a connection.
func create_host_bound(out_bandwidth: int = 0) -> intError#
Creates an ENetHost bound to the given bind_address and bind_port that allows up to max_peers connected peers, each allocating up to max_channels channels, optionally limiting bandwidth to in_bandwidth and out_bandwidth (if greater than zero).
Note: It is necessary to create a host in both client and server in order to establish a connection.
func destroy() -> void#
Destroys the host and all resources associated with it.
func dtls_client_setup(client_options: TLSOptions = null) -> intError#
Configure this ENetHost to use the custom Godot extension allowing DTLS encryption for ENet clients. Call this before connect_to_host to have ENet connect using DTLS validating the server certificate against hostname. You can pass the optional client_options parameter to customize the trusted certification authorities, or disable the common name verification. See TLSOptions.client and TLSOptions.client_unsafe.
func dtls_server_setup(server_options: TLSOptions) -> intError#
Configure this ENetHost to use the custom Godot extension allowing DTLS encryption for ENet servers. Call this right after create_host_bound to have ENet expect peers to connect using DTLS. See TLSOptions.server.
func flush() -> void#
Sends any queued packets on the host specified to its designated peers.
const func get_local_port() -> int#
Returns the local port to which this peer is bound.
const func get_max_channels() -> int#
Returns the maximum number of channels allowed for connected peers.
func get_peers() -> ENetPacketPeer[]#
Returns the list of peers associated with this host.
Note: This list might include some peers that are not fully connected or are still being disconnected.
func pop_statistic(statistic: int enumENetConnection.HostStatistic) -> float#
Returns and resets host statistics. See HostStatistic for more info.
func refuse_new_connections(refuse: bool) -> void#
Configures the DTLS server to automatically drop new connections.
Note: This method is only relevant after calling dtls_server_setup.
func service(timeout: int = 0) -> Array#
Waits for events on this connection and shuttles packets between the host and its peers, with the given timeout (in milliseconds). The returned Array will have 4 elements. An EventType, the ENetPacketPeer which generated the event, the event associated data (if any), the event associated channel (if any). If the generated event is 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.
Note: This method must be called on both ends involved in the event (sending and receiving hosts).
func socket_send(packet: PackedByteArray) -> void#
Sends a 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 STUN 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.
Annotations #
Constants #
const COMPRESS_NONE = 0 enum CompressionMode#
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.
const COMPRESS_RANGE_CODER = 1 enum CompressionMode#
ENet's built-in range encoding. Works well on small packets, but is not the most efficient algorithm on packets larger than 4 KB.
const COMPRESS_FASTLZ = 2 enum CompressionMode#
FastLZ compression. This option uses less CPU resources compared to COMPRESS_ZLIB, at the expense of using more bandwidth.
const COMPRESS_ZLIB = 3 enum CompressionMode#
Zlib compression. This option uses less bandwidth compared to COMPRESS_FASTLZ, at the expense of using more CPU resources.
const COMPRESS_ZSTD = 4 enum CompressionMode#
Zstandard 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.
const EVENT_ERROR = -1 enum EventType#
An error occurred during service. You will likely need to destroy the host and recreate it.
const EVENT_NONE = 0 enum EventType#
No event occurred within the specified time limit.
const EVENT_CONNECT = 1 enum EventType#
A connection request initiated by enet_host_connect has completed. The array will contain the peer which successfully connected.
const EVENT_DISCONNECT = 2 enum EventType#
A peer has disconnected. This event is generated on a successful completion of a disconnect initiated by ENetPacketPeer.peer_disconnect, if a peer has timed out, or if a connection request initialized by 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.
const EVENT_RECEIVE = 3 enum EventType#
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.
const HOST_TOTAL_SENT_DATA = 0 enum HostStatistic#
Total data sent.
const HOST_TOTAL_SENT_PACKETS = 1 enum HostStatistic#
Total UDP packets sent.
const HOST_TOTAL_RECEIVED_DATA = 2 enum HostStatistic#
Total data received.
const HOST_TOTAL_RECEIVED_PACKETS = 3 enum HostStatistic#
Total UDP packets received.
Constructors #
Enums #
CompressionMode#
enum CompressionMode {
COMPRESS_NONE = 0,
COMPRESS_RANGE_CODER = 1,
COMPRESS_FASTLZ = 2,
COMPRESS_ZLIB = 3,
COMPRESS_ZSTD = 4,
}EventType#
enum EventType {
EVENT_ERROR = -1,
EVENT_NONE = 0,
EVENT_CONNECT = 1,
EVENT_DISCONNECT = 2,
EVENT_RECEIVE = 3,
}HostStatistic#
enum HostStatistic {
HOST_TOTAL_SENT_DATA = 0,
HOST_TOTAL_SENT_PACKETS = 1,
HOST_TOTAL_RECEIVED_DATA = 2,
HOST_TOTAL_RECEIVED_PACKETS = 3,
}