Skip to content

Commit 1923153

Browse files
authored
Merge pull request #670 from jonbonazza/update-websocket-minimal
feat: update websocket-minimal to gdscript2.0
2 parents 5875f2a + d047c2d commit 1923153

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
[gd_scene load_steps=3 format=2]
1+
[gd_scene load_steps=3 format=3 uid="uid://cxaa046x45suv"]
22

3-
[ext_resource path="res://server.gd" type="Script" id=1]
4-
[ext_resource path="res://client.gd" type="Script" id=2]
3+
[ext_resource type="Script" path="res://server.gd" id="1"]
4+
[ext_resource type="Script" path="res://client.gd" id="2"]
55

66
[node name="Main" type="Node"]
77

88
[node name="Server" type="Node" parent="."]
9-
script = ExtResource( 1 )
9+
script = ExtResource( "1" )
1010

1111
[node name="Client" type="Node" parent="."]
12-
script = ExtResource( 2 )
12+
script = ExtResource( "2" )

networking/websocket_minimal/client.gd

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
extends Node
22

33
# The URL we will connect to.
4-
export var websocket_url = "ws://localhost:9080"
4+
@export
5+
var websocket_url = "ws://localhost:9080"
56

67
# Our WebSocketClient instance.
78
var _client = WebSocketClient.new()
89

910
func _ready():
1011
# Connect base signals to get notified of connection open, close, and errors.
11-
_client.connect("connection_closed", self, "_closed")
12-
_client.connect("connection_error", self, "_closed")
13-
_client.connect("connection_established", self, "_connected")
12+
_client.connect("connection_closed", _closed)
13+
_client.connect("connection_error", _closed)
14+
_client.connect("connection_established", _connected)
1415
# This signal is emitted when not using the Multiplayer API every time
1516
# a full packet is received.
1617
# Alternatively, you could check get_peer(1).get_available_packets() in a loop.
17-
_client.connect("data_received", self, "_on_data")
18+
_client.connect("data_received", _on_data)
1819

1920
# Initiate connection to the given URL.
2021
var err = _client.connect_to_url(websocket_url)
@@ -36,7 +37,7 @@ func _connected(proto = ""):
3637
print("Connected with protocol: ", proto)
3738
# You MUST always use get_peer(1).put_packet to send data to server,
3839
# and not put_packet directly when not using the MultiplayerAPI.
39-
_client.get_peer(1).put_packet("Test packet".to_utf8())
40+
_client.get_peer(1).put_packet("Test packet".to_utf8_buffer())
4041

4142

4243
func _on_data():

networking/websocket_minimal/project.godot

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
; [section] ; section goes between []
77
; param=value ; assign values to parameters
88

9-
config_version=4
9+
config_version=5
1010

1111
[application]
1212

1313
config/name="WebSocket Minimal Demo"
1414
config/description="This is a minimal sample of connecting two peers to each other using websockets."
1515
run/main_scene="res://Main.tscn"
16+
config/features=PackedStringArray("4.0")
1617

1718
[rendering]
1819

networking/websocket_minimal/server.gd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ var _server = WebSocketServer.new()
88
func _ready():
99
# Connect base signals to get notified of new client connections,
1010
# disconnections, and disconnect requests.
11-
_server.connect("client_connected", self, "_connected")
12-
_server.connect("client_disconnected", self, "_disconnected")
13-
_server.connect("client_close_request", self, "_close_request")
11+
_server.connect("client_connected", _connected)
12+
_server.connect("client_disconnected", _disconnected)
13+
_server.connect("client_close_request", _close_request)
1414
# This signal is emitted when not using the Multiplayer API every time a
1515
# full packet is received.
1616
# Alternatively, you could check get_peer(PEER_ID).get_available_packets()
1717
# in a loop for each connected peer.
18-
_server.connect("data_received", self, "_on_data")
18+
_server.connect("data_received", _on_data)
1919
# Start listening on the given port.
2020
var err = _server.listen(PORT)
2121
if err != OK:
2222
print("Unable to start server")
2323
set_process(false)
2424

2525

26-
func _connected(id, proto):
26+
func _connected(id, proto, rname):
2727
# This is called when a new peer connects, "id" will be the assigned peer id,
2828
# "proto" will be the selected WebSocket sub-protocol (which is optional)
29-
print("Client %d connected with protocol: %s" % [id, proto])
29+
print("Client %d connected with protocol %s and resource name %s" % [id, proto, rname])
3030

3131

3232
func _close_request(id, code, reason):

0 commit comments

Comments
 (0)