Not connect to socket io server on android
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.
try upgrading unity; see https://github.com/itisnajim/SocketIOUnity/issues/36
@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.
try these: https://github.com/itisnajim/SocketIOUnity/issues/60
it's not connecting with il2cpp in unity android
Anyone found a fix for this? Cant get it to work on android on 2021.3.8f1
@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.
@devalvitec Nope, still not working. Updated the unity version, tried changing the build options.
Im also building with il2cpp if that matters
what are the error exactly you are getting ?
@devalvitec Im getting no errors, nothing happens. Not even the OnError gets called.
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
@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
@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:
https://github.com/doghappy/socket.io-client-csharp/issues/94
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
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() };