Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser
Quick Information
Async Socket
Single thread async socket support for Godot 4.
Supported Engine Version
4.0
Version String
1.0
License Version
MIT
Support Level
testing
Modified Date
2 years ago
Git URL
Issue URL
Asynchronous Socket
Single thread async socket support for Godot 4.
TcpClient
wrap_stream(stream: StreamPeerTCP)
- Upgrade aStreamPeerTCP
to a asyncTcpClient
.connect_to_host(host: String, port: int) -> Error
- Open a connection (just like the normal one).disconnect_from_host()
- Yep, just like the other one.poll()
- It will refresh the connection status and receive data into the internal buffer.send(buffer: PackedByteArray) -> Error
- The same asput_data
fromStreamPeer
send_line(text: String) -> Error
- It will automatically append a LF at the end of thetext
.recv(length: int) -> PackedByteArray
- Coroutine that yields when that amount of bytes is ready to be read.recv_line() -> String
- Coroutine that yields when a new line is available to be read.
TcpListener
start()
- Start listening.stop()
- Stop listening.poll()
- Update all connected clients.accept() -> TcpClient
- Couroutine that yields when a new connection is ready to be accepted.
Examples:
Server
func _handle_server() -> void:
_server = TcpListener.new(5000)
_server.start()
var client: TcpClient = await _server.accept()
print("S> client connected")
client.send_line("<0>'e' n=Server</0>")
print("S> line sent")
await get_tree().create_timer(1).timeout
client.disconnect_from_host()
Client
func _handle_client() -> void:
_client = TcpClient.new()
_client.connect_to_host("127.0.0.1", 5000)
await _client.connected
print("C> connected")
_client.send_line("<0>'e'</0>")
var line = await _client.recv_line()
while line != "":
print("C> '%s'" % line.replace('\n', ''))
line = await _client.recv_line()
await _client.disconnected
print("C> disconnected")
Single thread async socket support for Godot 4.
Reviews
Quick Information
Async Socket
Single thread async socket support for Godot 4.
Supported Engine Version
4.0
Version String
1.0
License Version
MIT
Support Level
testing
Modified Date
2 years ago
Git URL
Issue URL