gdDocumentation0.8.0

API reference

GDUDPPacketConn

UDP endpoint preserving packet boundaries and source addresses, with deadlines and Close wakeups.

Methods

read_from

read_from(max: int = 65536) -> Dictionary, Err

Start receiving the next UDP packet.

Parameters

NameTypeDefaultDescription
maxint65536Maximum bytes requested by one receive operation.

Return value

Dictionary, Err

Suspends only the calling routine until the operation completes. No explicit await is needed.

Errors

The result carries a value and an Err. Check the error before using the value; a failure may retain partial progress. In a function returning value, Err, use ? to propagate failure to the caller. The ! operator terminates the program on failure; in serve it fails the current handler.

Returns a dictionary with data, host, port, and truncated. Packets are never merged.

read_from_async

read_from_async(max: int = 65536) -> await Dictionary, Err

Start receiving the next UDP packet.

Parameters

NameTypeDefaultDescription
maxint65536Maximum bytes requested by one receive operation.

Return value

await Dictionary, Err

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

The result carries a value and an Err. Check the error before using the value; a failure may retain partial progress. In a function returning value, Err, use ? to propagate failure to the caller. The ! operator terminates the program on failure; in serve it fails the current handler.

Returns a dictionary with data, host, port, and truncated. Packets are never merged.

write_to

write_to(data: PackedByteArray, host: String, port: int) -> int, Err

Start sending a UDP packet to an IP address.

Parameters

NameTypeDefaultDescription
dataPackedByteArrayRequiredInput data in the representation shown by the parameter type.
hostStringRequiredHostname or IP address used for connecting or binding.
portintRequiredNetwork port number. A listening port of zero lets the OS select a port.

Return value

int, Err

Suspends only the calling routine until the operation completes. No explicit await is needed.

Errors

The result carries a value and an Err. Check the error before using the value; a failure may retain partial progress. In a function returning value, Err, use ? to propagate failure to the caller. The ! operator terminates the program on failure; in serve it fails the current handler.

write_to_async

write_to_async(data: PackedByteArray, host: String, port: int) -> await int, Err

Start sending a UDP packet to an IP address.

Parameters

NameTypeDefaultDescription
dataPackedByteArrayRequiredInput data in the representation shown by the parameter type.
hostStringRequiredHostname or IP address used for connecting or binding.
portintRequiredNetwork port number. A listening port of zero lets the OS select a port.

Return value

await int, Err

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

The result carries a value and an Err. Check the error before using the value; a failure may retain partial progress. In a function returning value, Err, use ? to propagate failure to the caller. The ! operator terminates the program on failure; in serve it fails the current handler.

set_deadline

set_deadline(seconds: float) -> Err

Set both UDP receive and send deadlines.

Parameters

NameTypeDefaultDescription
secondsfloatRequiredDeadline setting in seconds; see this method for relative-time and clearing semantics.

Return value

Err

Errors

Returns an Err object directly, not a value-and-error pair. An absent error is null; inspect the method description to distinguish creation, lookup, and stored failure.

set_read_deadline

set_read_deadline(seconds: float) -> Err

Apply the UDP receive deadline to existing waits too.

Parameters

NameTypeDefaultDescription
secondsfloatRequiredDeadline setting in seconds; see this method for relative-time and clearing semantics.

Return value

Err

Errors

Returns an Err object directly, not a value-and-error pair. An absent error is null; inspect the method description to distinguish creation, lookup, and stored failure.

set_write_deadline

set_write_deadline(seconds: float) -> Err

Apply the UDP send deadline to existing waits too.

Parameters

NameTypeDefaultDescription
secondsfloatRequiredDeadline setting in seconds; see this method for relative-time and clearing semantics.

Return value

Err

Errors

Returns an Err object directly, not a value-and-error pair. An absent error is null; inspect the method description to distinguish creation, lookup, and stored failure.

addr

addr() -> Dictionary

Return the UDP endpoint's listen address.

Parameters

No parameters.

Return value

Dictionary

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

is_open

is_open() -> bool

Check whether the UDP endpoint is open.

Parameters

No parameters.

Return value

bool

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

close

close() -> void

Close the UDP endpoint and wake all pending operations.

Parameters

No parameters.

Return value

void

No value is returned.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.