While I haven’t verified anything, a few observations:
In the 3.5 code posted above, network.GetPeer(1) returns a WebSocketPeer
In the 4.0 code, you’re already working with a WebSocketPeer object
So, from that point forward, things should be, at least, similar…
Further, in the 3.5 code, you make a GetPacket call on the WebSocketPeer object. Looking, the 4.0 version of WebSocketPeer also has a GetPacket method.
So, it seems like the above should just require a comparison of the related docs and some minimal refactoring to get workigng in Godot 4.
Turns out it was something along those lines, thanks for the help!
To summarize it, I connect the WebSocketClient’s “data_received” signal to the _DataReceived function to handle packets received there. However, this signal (as far as I can tell) was removed in Gd4. In order to tackle this problem, I just followed the steps in the WebSocketPeer documentation which for some reason I missed even though I visited the page a bunch of times! Here’s the result:
public override void _Process(double delta) {
network.Poll();
WebSocketPeer.State state = network.GetReadyState();
if (state == WebSocketPeer.State.Open) {
while (network.GetAvailablePacketCount() > 0) {
deconstruct_message(utf8.GetString(network.GetPacket()));
}
} else if (state == WebSocketPeer.State.Closed) {
int code = network.GetCloseCode();
string reason = network.GetCloseReason();
GD.Print("Disconnected from server: code:", code, " reason:", reason);
SetProcess(false);
}
}