An ENet wrapper for Godot 3.

GDNet

An ENet wrapper for Godot.

GDNet for Godot 3. If you need to use GDNet for Godot 2.1+, you can find it here.

About

ENet is a library that provides a number of features on top of UDP such as, connection handling, sequencing, reliability, channels, bandwidth throttling, packet fragmentation and reassembly. GDNet provides a (mostly) thin wrapper around ENet.

Installation

Simply drop the code into a gdnet3 directory in your godot/modules directory and build for the platfom of your choice. GDNet has been verified to build on Linux (64 bit), MacOS X (32/64 bit), and Windows (32/64 bit cross-compiled using MinGW).

Example

extends Node

var client1 = null
var client2 = null
var peer1 = null
var peer2 = null
var server = null

func _init():
	var address = GDNetAddress.new()
	address.set_host("localhost")
	address.set_port(3000)

	server = GDNetHost.new()
	server.bind(address)

	client1 = GDNetHost.new()
	client1.bind()
	peer1 = client1.host_connect(address)

	client2 = GDNetHost.new()
	client2.bind()
	peer2 = client2.host_connect(address)

func _process(delta):
	if (client1.is_event_available()):
		var event = client1.get_event()

		if (event.get_event_type() == GDNetEvent.CONNECT):
			print("Client1 connected")
			peer1.send_var("Hello from client 1", 0)

		if (event.get_event_type() == GDNetEvent.RECEIVE):
			print(event.get_var())

	if (client2.is_event_available()):
		var event = client2.get_event()

		if (event.get_event_type() == GDNetEvent.CONNECT):
			print("Client2 connected")
			peer2.send_var("Hello from client 2", 0)

		if (event.get_event_type() == GDNetEvent.RECEIVE):
			print(event.get_var())

	if (server.is_event_available()):
		var event = server.get_event()

		if (event.get_event_type() == GDNetEvent.CONNECT):
			var peer = server.get_peer(event.get_peer_id())
			var address = peer.get_address();
			print("Peer connected from ", address.get_host(), ":", address.get_port())
			peer.send_var(str("Hello from server to peer ", event.get_peer_id()), 0)

		elif (event.get_event_type() == GDNetEvent.RECEIVE):
			print(event.get_var())
			server.broadcast_var("Server broadcast", 0)

Sample Output:

Client1 connected
Client2 connected
Peer connected from 127.0.0.1:56075
Peer connected from 127.0.0.1:42174
Hello from server to peer 0
Hello from client 2
Hello from server to peer 1
Server broadcast
Hello from client 1
Server broadcast
Server broadcast
Server broadcast

API

GDNetAddress

  • set_port(port:Integer)
  • get_port():Integer
  • set_host(host:String)
  • get_host():String

GDNetEvent

  • get_event_type():Integer - returns one of GDNetEvent.CONNECT, GDNetEvent.DISCONNECT, or GDNetEvent.RECEIVE
  • get_peer_id():Integer - the peer associated with the event
  • get_channel_id():Integer - only valid for GDNetEvent.RECEIVE events
  • get_packet():PoolByteArray - only valid for GDNetEvent.RECEIVE events
  • get_var():Variant - only valid for GDNetEvent.RECEIVE events
  • get_data():Integer - only valid for GDNetEvent.CONNECT and GDNetEvent.DISCONNECT events

GDNetHost

  • get_peer(id:Integer):GDNetPeer
  • set_event_wait(id:Integer) - sets the duration of time the host thread will wait (block) for events (default: 1 ms)
  • set_max_peers(max:Integer) - must be called before bind (default: 32)
  • set_max_channels(max:Integer) - must be called before bind (default: 1)
  • set_max_bandwidth_in(max:Integer) - measured in bytes/sec, must be called before bind (default: unlimited)
  • set_max_bandwidth_out(max:Integer) - measured in bytes/sec, must be called before bind (default: unlimited)
  • bind(addr:GDNetAddress) - starts the host (the system determines the interface/port to bind if addr is empty)
  • unbind() - stops the host
  • host_connect(addr:GDNetAddress, data:Integer):GDNetPeer - attempt to connect to a remote host (data default: 0)
  • broadcast_packet(packet:PoolByteArray, channel_id:Integer, type:Integer) - type must be one of GDNetMessage.UNSEQUENCED, GDNetMessage.SEQUENCED, or GDNetMessage.RELIABLE
  • broadcast_var(var:Variant, channel_id:Integer, type:Integer) - type must be one of GDNetMessage.UNSEQUENCED, GDNetMessage.SEQUENCED, or GDNetMessage.RELIABLE
  • is_event_available():Boolean - returns true if there is an event in the queue
  • get_event_count():Integer - returns the number of events in the queue
  • get_event():GDNetEvent - return the next event in the queue

GDNetPeer

These methods should be called after a successful connection is established, that is, only after a GDNetEvent.CONNECT event is consumed.

  • get_peer_id():Integer
  • get_address():GDNetAddress
  • ping() - sends a ping to the remote peer
  • set_ping_interval(pingInterval:Integer) - Sets the interval at which pings will be sent to a peer
  • get_avg_rtt():Integer - Average Round Trip Time (RTT). Note, this value is initially 500 ms and will be adjusted by traffic or pings.
  • reset() - forcefully disconnect a peer (foreign host is not notified)
  • peer_disconnect(data:Integer) - request a disconnection from a peer (data default: 0)
  • disconnect_later(data:Integer) - request disconnection after all queued packets have been sent (data default: 0)
  • disconnect_now(data:Integer) - forcefully disconnect peer (notification is sent, but not guaranteed to arrive) (data default: 0)
  • send_packet(packet:PoolByteArray, channel_id:int, type:int) - type must be one of GDNetMessage.UNSEQUENCED, GDNetMessage.SEQUENCED, or GDNetMessage.RELIABLE
  • send_var(var:Variant, channel_id:Integer, type:Integer) - type must be one of GDNetMessage.UNSEQUENCED, GDNetMessage.SEQUENCED, or GDNetMessage.RELIABLE
  • set_timeout(limit:int, min_timeout:Integer, max_timeout:Integer)
    • limit - A factor that is multiplied with a value that based on the average round trip time to compute the timeout limit.
    • min_timeout - Timeout value, in milliseconds, that a reliable packet has to be acknowledged if the variable timeout limit was exceeded before dropping the peer.
    • max_timeout - Fixed timeout in milliseconds for which any packet has to be acknowledged before dropping the peer.

License

Copyright (c) 2015 James McLean
Licensed under the MIT license.

Owner
perdugames
while(true) { random(existence || nonexistence) ? break; : continue; };
perdugames
Similar Resources

A TCP Wrapper to use QSVEncC "Remotely"*

TCP Wrapper for QSVEncC This is a tcp wrapper implementation for QSVEncC command from QSVEnc, simply sending the input & args to the server-side, and

Dec 19, 2021

Go built-in package network address wrapper.

osnet Go built-in package network address wrapper. Installation go get -u github.com/coolstina/osnet functions IsIP: Check whether the IP address is r

Jan 10, 2022

A wrapper for exposing a shared endpoint for Google Cloud Functions in go. API styled after Node.JS firebase-functions package.

firebase-fx A wrapper for Google Cloud Functions that simplifies the deployment of serverless applications. Meant to expose a similar API to the Fireb

Nov 7, 2022

Golang unix-socket wrapper

Sockunx Golang unix-socket wrapper Server Running server server, e := sockunx.NewServer("/path/to/your/socks.sock", 512) if e != nil { log.Fatal(e

Jan 17, 2022

Wrapper for Lightning Network Daemon (lnd). It provides separate accounts with minimum trust for end users.

LndHub.go Wrapper for Lightning Network Daemon (lnd). It provides separate accounts with minimum trust for end users. LndHub compatible API implemente

Dec 21, 2022

Wrapper around bufcli to make it do cross-repo compiles for private repos and use full paths.

Wrapper around bufcli to make it do cross-repo compiles for private repos and use full paths.

Bufme A tool for compiling protos with full directory paths and cross repo compiles. Introduction Protocol buffers rock, but protoc should die in a fi

Feb 5, 2022

An unofficial GUI wrapper around the Tailscale CLI client.

An unofficial GUI wrapper around the Tailscale CLI client.

Trayscale Trayscale is an unofficial GUI wrapper around the Tailscale CLI client, particularly for use on Linux, as no official Linux GUI client exist

Dec 26, 2022

Golang terminal ANSI OSC52 wrapper. Copy text to clipboard from anywhere.

go-osc52 A terminal Go library to copy text to clipboard from anywhere. It does so using ANSI OSC52. The Copy() function defaults to copying text from

Dec 6, 2022

ClashWebLite is a cross-platform lightweighted wrapper for Clash Premium on Desktop environment.

ClashWebLite is a cross-platform lightweighted wrapper for Clash Premium on Desktop environment.

ClashWebLite ClashWebLite is a cross-platform lightweighted wrapper for Clash Premium on Desktop environment. http://127.0.0.1:9090/ui: Features Suppo

Dec 29, 2022
Related tags
A protoc-gen-go wrapper including an RPC stub generator

// Copyright 2013 Google. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE fi

Nov 17, 2022
go http wrapper for boomer

什么是 go-httpwrapper? 如果你想快速实现http协议的分布式压测,那么go-httpwrapper将会是一个不错的选择! Boomer 是Locust框架worker端的go实现,它很好地弥补了Locust使用Python实现而导致性能不佳的缺陷。 go-httpwrapper对Bo

May 5, 2022
A vote botting wrapper for GoLang designed for Minecraft: Pocket Servers.

libvote A vote botting wrapper for GoLang designed for Minecraft: Pocket Servers by Jviguy and JustTal. Disclaimer Usage of libvote requires your own

Apr 17, 2022
golang http server wrapper

Yong Simple Web Framework This project benchmarked gin-gonic. Installation Go command to install Yong. $ go get -u github.com/rladyd818/yong Import it

May 12, 2021
Go wrapper for gram-tgcalls.
Go wrapper for gram-tgcalls.

Go wrapper for gram-tgcalls. Features Doesn't let you worry about running Telegram clients, it starts an unlimited number of lightweight Gra

Dec 8, 2021
Small wrapper for containers/image which exposes a HTTP API to fetch

CLI to expose containers/image fetching via HTTP This is a small CLI program which vendors the containers/image Go library and exposes a HTTP API to f

Nov 1, 2021
A simple wrapper for ssh to select profiles.
A simple wrapper for ssh to select profiles.

qSSH A simple wrapper for ssh to select profiles from your ~/.ssh/config file. Can be aliased to ssh Installation Download binary from Releases, or bu

Nov 9, 2021
SFTP client simple wrapper.
SFTP client simple wrapper.

Installation go get -u github.com/coolstina/sftpclient Example package main import ( "fmt" "log" "os" "github.com/coolstina/sftpclient" ) func

Nov 3, 2021
Go wrapper around Device Console Windows tool.

go-devcon Go wrapper around the Windows Device Console (devcon.exe). go install github.com/mikerourke/go-devcon Introduction Here's a brief overview

Nov 4, 2021
A wrapper for cloudflared that manages your local proxies for you

Cloudflared Tunnel Wrapper cfdtunnel is a wrapper for cloudflared access tunnel, designed to access multiple tunnels without having to worry about you

Dec 16, 2022