WebSocket

An asset by AndreaTerenz
The page banner background of a mountain and forest
WebSocket hero image

Quick Information

0 ratings
WebSocket icon image
AndreaTerenz
WebSocket

Wrapper node for WebSocketPeer (Godot 4.x)

Supported Engine Version
4.0
Version String
1.0
License Version
MIT
Support Level
community
Modified Date
1 year ago
Git URL
Issue URL

WebSocket

Godot 4 addon - wrapper node for WebSocketPeer. It basically restores the "node-based" implementation of WebSockets from Godot 3.X

Installation

Clone the repo and copy the addons/websocket folder into your project's addons folder. Activate the plugin in the project's settings and you're good to go.

Usage

The WebSocket node is a wrapper around a WebSocketPeer object, abstracting most of its usage.

Note that, unless specified otherwise, the node will send and receive data as arrays of bytes.

Signals

It provides the following signals:

  • connected(url), emitted when the socket successfully connects to url
  • connect_failed, emitted when the socket fails to connect
  • received(data), emitted when the socket is done receiveing some data
  • closing, emitted when the socket starts closing down
  • closed(code, reason), emitted when the socket connection is closed; code is one of the standard WebSocket codes, and reason is a human readable explanation for the closure of the connection

@export Parameters

@export_range(0, 128) var receive_limit : int = 0        # Max number of packets to receive before emitting received(data) - 0 == no limit
@export_range(0, 300) var connection_timeout : int = 10  # Seconds to wait in the CONNECTING state before declaring the connection failed
@export_group("Routing")
@export var host := "127.0.0.1"  # Hostname to connect to
@export var route := "/"         # URL Route to connect to - a server may serve different websocket connections on different routes
@export var use_WSS := true      # If true, use secure WSS protocol instead of WS - may need to be false for localhost connections
@export_group("Autoconnect")     # See below in Features/Autoconnect
@export var autoconnect_mode := AUTOCONNECT_MODE.NONE
@export var autoconnect_reference : Node = null

Autoconnect

The node can be setup to automatically try connecting when a given node is ready. The options are:

enum AUTOCONNECT_MODE {
    NONE,          # No autoconnect, will need to be connected manually - default
    SELF_READY,    # Autoconnect when the WebSocket node is ready
    PARENT_READY,  # Wait for parent node to be ready (if not null)
    OWNER_READY,   # Wait for owner node to be ready (if not null)
    ROOT_READY,    # Wait for root node to be ready
    CUSTOM,        # Wait for the node specified in autoconnect_reference to be ready (if not null and if not already loaded)
}

Wrapper node for WebSocketPeer (Godot 4.x)

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
WebSocket icon image
AndreaTerenz
WebSocket

Wrapper node for WebSocketPeer (Godot 4.x)

Supported Engine Version
4.0
Version String
1.0
License Version
MIT
Support Level
community
Modified Date
1 year ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers