Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not connect to socket io server on android #33

Open
DamaSistem opened this issue Nov 23, 2022 · 15 comments
Open

Not connect to socket io server on android #33

DamaSistem opened this issue Nov 23, 2022 · 15 comments

Comments

@DamaSistem
Copy link

Hi there, I couldn't get it to connect on the Android phone. It works fine in Unity editor. Scripting backend IL2CPP api Compatibility level .Net Framework. I also use server-side codes in another react native application. I don't think there is a problem on the server side. Socket versions Unity side v1.0.0 , server side v4.1.3. I opened a project from scratch and pulled the unity side to v1.1.3 and the server side to v4.5.4, but it still didn't work. I would be glad if you can help.

@itisnajim
Copy link
Owner

try upgrading unity;
see #36

@devalvitec
Copy link

@itisnajim I am using the unity 2021.3.30f1 LTS version but I am not able to connect to the server on mobile devices, it's connecting fine with the editor.

Any help is highly appreciated.

@itisnajim
Copy link
Owner

try these:
#60

@AtulAbhiwan03
Copy link

it's not connecting with il2cpp in unity android

@ScottasM
Copy link

Anyone found a fix for this? Cant get it to work on android on 2021.3.8f1

@devalvitec
Copy link

@ScottasM update your Unity to 2022.3.10f1 or Change and try between the Faster (smaller) builds option/ Faster runtime option at player setting for Android. Faster runtime option might work.

@ScottasM
Copy link

@devalvitec Nope, still not working. Updated the unity version, tried changing the build options.

@ScottasM
Copy link

Im also building with il2cpp if that matters

@devalvitec
Copy link

what are the error exactly you are getting ?

@ScottasM
Copy link

ScottasM commented Nov 1, 2023

@devalvitec Im getting no errors, nothing happens. Not even the OnError gets called.

@ScottasM
Copy link

ScottasM commented Nov 3, 2023

Okay, after 4 days of this torture i fixed it.
for any other lost souls out there here what was wrong :
Apparently android didnt trust my ssl certificate, and didnt print anything to logcat, so when i added all the events like OnReconnectFail, OnRecconectAttempt and etc. i finally saw the error.

what i had to do was :
cat certificate.crt ca_bundle.crt > chained.pem to generate the chained.pem file for android to trust

and then in my flask socketio app i changed the path to point from certificate.crt to chained.pem

@joyscoreinc
Copy link

@ScottasM
I've deployed my solution on cloud run so your solution can't be applied
The library must provide a way to set supported TLS encyrption like this
https://stackoverflow.com/questions/68268113/how-can-unity-connect-with-secure-websocket-based-on-node-js/68280594#68280594

@itisnajim
Copy link
Owner

@ScottasM

I've deployed my solution on cloud run so your solution can't be applied

The library must provide a way to set supported TLS encyrption like this

https://stackoverflow.com/questions/68268113/how-can-unity-connect-with-secure-websocket-based-on-node-js/68280594#68280594

Try this if solve your issue:

doghappy/socket.io-client-csharp#94

@TiagoAndreAlmeida
Copy link

TiagoAndreAlmeida commented Feb 15, 2024

hey guys i stuck on this issue too, on local work on unity editor and android. but when trying to connect to server nothing happens.
i can connect to my remote server with my reactjs app normaly, just the unity no connect.
Unity version: 2023.3.34f1
this is my code on Unity:

`
socket = new SocketIOUnity(uri_url, new SocketIOOptions
{
EIO = 4
,
Transport = SocketIOClient.Transport.TransportProtocol.Polling
})
{
JsonSerializer = new NewtonsoftJsonSerializer()
};

    ///// reserved socketio events
    socket.OnConnected += (sender, e) =>
    {
        Debug.Log("socket.OnConnected");
    };
    socket.OnPing += (sender, e) =>
    {
        Debug.Log("Ping");
    };
    socket.OnPong += (sender, e) =>
    {
        Debug.Log("Pong: " + e.TotalMilliseconds);
    };
    socket.OnDisconnected += (sender, e) =>
    {
        Debug.Log("disconnect: " + e);
    };
    socket.OnReconnectAttempt += (sender, e) =>
    {
        Debug.Log($"OnReconnectAttempt: attempt = {e}");
    };
    socket.OnReconnectError += (sender, e) =>
    {
        Debug.Log($"OnReconnectError: attempt = {e}");
    };
    socket.OnReconnectFailed += (sender, e) =>
    {
        Debug.Log($"OnReconnectFailed: attempt = {e}");
    };
    socket.On("game", (response) =>
    {
        gameInfor = response.GetValue<WebsocketMessage>();
        if (gameInfor.eventType == "winner" && gameInfor.userId == userObject.userUid)
        {
            userObject.bolhas += gameInfor.amount;
            winnerColor = gameInfor.color;
            Debug.Log($"GANHOU {winnerColor} - {gameInfor.userId} - {gameInfor.eventType}");
        }
    });
    socket.ConnectAsync();
    `

i trying to use TransportProtocol.Polling and TransportProtocol.WebSocket but still same problem
on my reactjs app i connect to my socket io server using https protocol.
dont know what to do about this more

@TiagoAndreAlmeida
Copy link

i fix after doing this
o SocketIOOptions, i set AutoUpgrade to false.
now on my looks like this:
socket = new SocketIOUnity(uri_url, new SocketIOOptions { AutoUpgrade = false, EIO = 4 , Transport = SocketIOClient.Transport.TransportProtocol.Polling }) { JsonSerializer = new NewtonsoftJsonSerializer() };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants