PLS HELP! Can't get nano 33 IoT to connect to websocket server

I am using WebSockets by Markus Sattler. I know it is not an issue with the server, as I have been able to connect to the server with ArduinoWebSockets by Gil Maimon, among other ways. I'm connected to the wifi and attempting to access a local server being hosted from my laptop on the same wifi. I made sure to allow incoming connections on the port (9000), so it's not a firewall issue either. I also tried multiple different versions of the library as I saw some threads saying it worked on certain versions. It seems to work fine, but gets caught on webSocket.begin(serverAddress, serverPort);. I would really appreciate any help, I have been stuck on this issue for ages.

#include <SPI.h>
#include <WiFiNINA.h>
#include <Arduino.h>
#include <WebSocketsClient.h>

#define SSID "---"
#define PASSWORD "---"

#define ECG_PIN A0

const char* serverAddress = "---";
const uint16_t serverPort = 9000;

FirebaseData fbdo;
WiFiClient wifi;
WebSocketsClient webSocket;

void setup() {
    Serial.begin(115200);
    WiFi.begin(SSID, PASSWORD);
    Serial.print("Connecting to Wi-Fi...");
    while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(300);
    }
    Serial.println();
    Serial.print("Connected to WiFi: ");
    Serial.println(SSID);

    // Initialize WebSocket
    webSocket.begin(serverAddress, serverPort);
}

void loop() {
    if (webSocket.isConnected()) {
       Serial.print("connected");
        //int ecgValue = analogRead(ECG_PIN);  // Read ECG signal
        //String ecgString = String(ecgValue); // Create a String object
        //webSocket.sendTXT(ecgString);        // Send ECG value as a string
        //delay(5);                            // Small delay to control sampling rate
    } else {
        Serial.println("WebSocket not connected, attempting to reconnect...");
        webSocket.begin(serverAddress, serverPort);
        delay(300);
    }
}
import asyncio
import websockets

async def receive_ecg(websocket):
    async for message in websocket:
        print(f"Received ECG Value: {message}")

async def main():
    server = await websockets.serve(receive_ecg, "0.0.0.0", 9000)
    print("WebSocket server started on ws://0.0.0.0:9000...")

    await server.wait_closed()

asyncio.run(main())

I had initially been trying to send ecg data which is being taken from an AD8232 that is wired to the Arduino, but I have altered the code to focus on just getting it to connect.

Looking at the github. Sadler has his connection from the client as
webSocket.begin("192.168.0.123", 81, "/");
Maybe try adding the backslash in your begin statement.

no same issue unfortunately.

SOLUTION. Use void webSocketEvent(), webSocket.onEvent(webSocketEvent); and webSocket.loop();

#include <SPI.h>
#include <WiFiNINA.h>
#include <Arduino.h>
#include <WebSocketsClient.h>

#define SSID ""
#define PASSWORD ""

#define ECG_PIN A0

const char* serverAddress = "";
const uint16_t serverPort = ;

WiFiClient wifi;
WebSocketsClient webSocket;

void webSocketEvent(WStype_t type, uint8_t *payload, size_t length) {

  switch (type) {
    case WStype_DISCONNECTED:
      Serial.println("[WSc] Disconnected!");
      break;
    case WStype_CONNECTED:
      Serial.println("[WSc] Connected!");

      // send message to server when Connected
      webSocket.sendTXT("Connected");
      break;
    case WStype_TEXT:
      Serial.print("[WSc] get text:");
      Serial.println((char *)payload);

      // send message to server
      // webSocket.sendTXT("message here");
      break;
    case WStype_BIN:
      // send data to server
      // webSocket.sendBIN(payload, length);
      break;
    case WStype_ERROR:
    case WStype_FRAGMENT_TEXT_START:
    case WStype_FRAGMENT_BIN_START:
    case WStype_FRAGMENT:
    case WStype_PING:
    case WStype_PONG:
    case WStype_FRAGMENT_FIN:
      break;
  }
}

void setup() {
    Serial.begin(115200);
      while (!Serial) {
      ;  // wait for serial port to connect. Needed for native USB port only
    }

    WiFi.begin(SSID, PASSWORD);
    Serial.print("Connecting to Wi-Fi...");
    while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        delay(300);
    }
    Serial.println();
    Serial.print("Connected to WiFi: ");
    Serial.println(SSID);

    // Initialize WebSocket
    webSocket.begin(serverAddress, serverPort);

    // event handler
    webSocket.onEvent(webSocketEvent);

    // try ever 5000 again if connection has failed
    webSocket.setReconnectInterval(5000);
}

void loop() {
   webSocket.loop();
}