0 votes

Hey,

I'm trying to connect to a Server on my local machine via Websocket. I'm using C# and my attempt to connect looks like this

using Godot;
using System;

public class WebsocketService {

    // private string URL = "ws://echo.websocket.org";
    private string URL = "ws://127.0.0.1:8080/ws-chat/123?name=Hostname";

    public WebsocketService() {
        Godot.WebSocketClient ws = new Godot.WebSocketClient();

        ws.ConnectToUrl(URL);
        GD.Print("Connected or not?? To " + URL);
        GD.Print(ws.GetConnectedHost());
    }

}

I get the following error

E 0:00:00.537   get_connected_host: Condition "!_peer->is_connected_to_host()" is true. Returned: IP_Address()
<C++ Source>  modules/websocket/wsl_client.cpp:318 @ get_connected_host()
<Stack Trace> :0 @ System.String Godot.NativeCalls.godot_icall_0_2(IntPtr , IntPtr )()
                WebSocketClient.cs:108 @ System.String Godot.WebSocketClient.GetConnectedHost()()
                WebsocketService.cs:18 @ WebsocketService..ctor()()
                Board.cs:17 @ Board..ctor()()

When using GDScript I have no problems to connect to my server via websocket.

Has anybody experience with this issue.

Thank you for your help

in Engine by (16 points)

2 Answers

0 votes

So at the end I had to create my own WebsocketClient to connect to my server.

by (16 points)
0 votes

Try:

private String URL = "ws://127.0.0.1:8080/ws-chat/123?name=Hostname";
private String[] supportedProtocols = new string[1]{"my-protocol"};
private Boolean multiplayer = false;
private Godot.WebSocketClient ws;

public override void _Ready()
{
    ws = new Godot.WebSocketClient();
    GD.Print(ws.ConnectToUrl(URL, supportedProtocols, multiplayer));
}
by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.