godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.89k stars 20.16k forks source link

[Godot 3.2 on Steam] WebSocketClient not working on IOS export #35935

Closed ThomasUijlen closed 4 years ago

ThomasUijlen commented 4 years ago

The WebSocketClient doesn't seem to work on IOS. I've tried it on Windows 10 and MacOs and it works fine. The server responds and sends a message back.

Once I try put_packet() it says "!is_connected_to_host() is true".

Here is my Godot code:


func _ready():
    if multiplayerActive:
        connection.connect("connection_established", self, "_connection_established")
        connection.connect("connection_closed", self, "_connection_closed")
        connection.connect("connection_error", self, "_connection_error")
        connection.connect("data_received ", self, "_data_received ")
        connection.connect_to_url("ws://157.245.73.106:8080/onlineShooter-1.0-SNAPSHOT/player/test")

func _connection_established(protocol):
    print("Connection established with protocol: ", protocol)
    print(connection.get_peer(1).is_connected_to_host())

func _connection_closed():
    print("Connection closed")

func _connection_error():
    print("Connection error")
    print(connection.get_peer(1))

func _process(delta):
    connection.get_peer(1).set_write_mode(0)
    connection.get_peer(1).put_packet((player.getPlayerArray()+"/"+str(get_parent().token)+"/"+str(get_parent().worldName)).to_utf8())

Here is my Java code:

@ServerEndpoint(value = "/player/{username}")
public class PlayerSocket {
    PlayerService playerService = new PlayerService();

    @OnOpen
    public void onOpen(){
        System.out.println("Open Connection ...");
    }

    @OnMessage
    public String onMessage(String playerString){
        Gson g = new Gson();
        String[] stringArray = playerString.split("/");
        PlayerDTO playerDTO = g.fromJson(stringArray[0], PlayerDTO.class);
        String token = stringArray[1];
        String worldName = stringArray[2];
        PlayerDTO player = playerService.verifyUser(token,worldName);
        playerService.movePlayer(playerDTO,player);
        List<PlayerDTO> players = playerService.getPlayers(token, worldName);
        return g.toJson(players);
    }

    @OnClose
    public void onClose(Session session) throws IOException {
        // WebSocket connection closes
    }

    @OnError
    public void onError(Session session, Throwable throwable) {
        // Do error handling here
    }
}

I have no idea what is causing this. This might be a bug but it might also just be a mistake I made. Am I doing anything wrong, is it not supported on IOS or am I doing something wrong?

(Lol sorry for all the edits, forgot there was a preview)

Calinou commented 4 years ago

Do HTTP requests to a service like https://httpbin.org/get work in the iOS export? You could try this to make sure it's not due to missing permissions. See this page for example code.

ThomasUijlen commented 4 years ago

Do HTTP requests to a service like https://httpbin.org/get work in the iOS export? You could try this to make sure it's not due to missing permissions. See this page for example code.

Before this I was using http requests for the multiplayer. The problem was that it was way to slow. Player movement was really laggy. My teacher told me to use websockets and it works 100x better then the http requests since its way faster.

The http requests work on IOS since I've tested it before. The websocket doesn't.

Calinou commented 4 years ago

cc @Faless – not sure if he has an iOS device though :slightly_smiling_face:

ThomasUijlen commented 4 years ago

cc @Faless – not sure if he has an iOS device though 🙂

Forgot to mension sorry. I have an Iphone 11 and Iphone 7 wich I've tested it on. They both don't work. I have the newest software update.

ThomasUijlen commented 4 years ago

@Calinou @Faless still hasn't responded. I'm currently unable to progress with my multiplayer since I can't properly test it. I know that a lot is going on with Godot 4.0 but I would extremely happy if this bug got resolved!

Faless commented 4 years ago

I don't have a Mac, nor another Apple device. But looking at the provided code it seems there are a few errors.

I don't see the websocket peer being polled anywhere, additionally you are calling put_packet in process which might happen before the connection is completed.

Have a look at websocket minimal and websocket chat demos here https://github.com/godotengine/godot-demo-projects/tree/master/networking/

On Thu, Feb 20, 2020, 23:40 swaggerbeer1 notifications@github.com wrote:

@Calinou https://github.com/Calinou @Faless https://github.com/Faless still hasn't responded. I'm currently unable to progress with my multiplayer since I can't properly test it. I know that a lot is going on with Godot 4.0 but I would extremely happy if this bug got resolved!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/35935?email_source=notifications&email_token=AAM4C3UYUKMBNLRVFTK62ZLRD4BE7A5CNFSM4KQRXMKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMQVSAI#issuecomment-589388033, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM4C3VZQGIV4E536UILNYTRD4BE7ANCNFSM4KQRXMKA .

Faless commented 4 years ago

Closing as this seems an error in the game logic (see comment above), and no additional info were provided after a while. Please comment if you can confirm it is an engine bug (e.g. by trying out the demos above), and I'll reopen it.