itisnajim / SocketIOUnity

A Wrapper for socket.io-client-csharp to work with Unity.
MIT License
393 stars 67 forks source link

Emit not working on android #32

Open Kouznetsov opened 1 year ago

Kouznetsov commented 1 year ago

The socket.Emit() function works correctly on the Editor. My android device receives the messages as expected, but when Emitting from android, nothing shows on the server or elsewhere. The code is the same on the Editor and the Android device.

itisnajim commented 1 year ago

duplicated ? https://github.com/itisnajim/SocketIOUnity/issues/12

Kouznetsov commented 1 year ago

I don't think so, the server is working fine. The same thing happens on iOS. Login and message receiving are working but nothing gets emitted. No error is raised either. The other thread suggests that android might be missing the internet permission but my game already uses internet without problem.

It might be related to the fact that my server is not running on https. The thing that's weird is that it still connects and receives messages. I expected everything to fail directly.

itisnajim commented 1 year ago

try these: https://github.com/doghappy/socket.io-client-csharp/issues/134 https://github.com/doghappy/socket.io-client-csharp/issues/129 https://github.com/doghappy/socket.io-client-csharp/issues/120 https://github.com/doghappy/socket.io-client-csharp/issues/113 https://github.com/doghappy/socket.io-client-csharp/issues/24 https://github.com/doghappy/socket.io-client-csharp/issues/5

and try to emit an empty event, something like: socket.Emit("eventName"); or different (player )build settings!

also build on pc/mac and see if this is only on android !? sometimes restarting the app can fix this if you are working on localhost or in a local network.

itisnajim commented 1 year ago

try updating unity see https://github.com/itisnajim/SocketIOUnity/issues/36

timbotimbo commented 10 months ago

For me this was caused by IL2CPP breaking the JSON serializer that is used by default. Simply switching to the Newtonsoft option (that's already included) makes Emit work on Android and iOS.

using SocketIOClient.Newtonsoft.Json;

socket = new SocketIOUnity( ... );
socket.JsonSerializer = new NewtonsoftJsonSerializer();
wstevenrodriguez commented 9 months ago

For me this was caused by IL2CPP breaking the JSON serializer that is used by default. Simply switching to the Newtonsoft option (that's already included) makes Emit work on Android and iOS.

using SocketIOClient.Newtonsoft.Json;

socket = new SocketIOUnity( ... );
socket.JsonSerializer = new NewtonsoftJsonSerializer();

it's works thanks