Disconnect all socket to when a scene change?

in unity client we have different files like matchCommunication manager,
Ui Update, state managment , Chatting e.t.c . we create different sockets for every files . can we disconnect socket when to change file. or can we disconnect all sockets when we change scene from GamePlay to Main Menu.

I strongly suggest you avoid creating a socket per file/feature/scene. It usually leads to tricky problems that you shouldn’t need to deal with: failure scenarios where some sockets may be open and some closed, increased device battery drain etc.

You should maintain one socket per client and use it everywhere you need access to realtime features. Consider using a pattern like the NakamaManager. This also means you don’t have to disconnect/reconnect the socket every time the scene changes.


in leave game method after LeaveMatchAsync called. is socketCloseAsync() should called?
await NakamaManager.Instance.Socket.LeaveMatchAsync(MatchId);

No, you should only disconnect the socket when you will no longer need it at all. This usually means the socket should only be closed when the application exits, otherwise it stays open waiting for the next match or chat channel usage.