mikerochip/unity-websocket

OnMessageReceived debouncing

edstef opened this issue · 3 comments

Hi, I just integrated this library switching over from https://github.com/endel/NativeWebSocket

I'm having issues using the event based approach you outline in the samples:

public class networking : MonoBehaviour
{

    public WebSocketConnection wsConnection;

...
void Awake()
    {
        DontDestroyOnLoad(gameObject);

        Connect();

        wsConnection.StateChanged += OnStateChanged;
        wsConnection.ErrorMessageReceived += OnErrorMessageReceived;
        wsConnection.MessageReceived += OnMessageReceived;
    }
...
 private void OnMessageReceived(WebSocketConnection connection, WebSocketMessage message)
    {
        Debug.Log("test")

I am seeing "test" printed upwards of 13 times for every socket message I send from the server. Do I need to debounce the message and if so is there a recommended approach?

The OnMessageReceived handler was changed back in July to not require you to do anything to remove the message from an internal list ecf87e8

If you're on an old version you can click the update button in Unity's package manager.

If you're on the latest already then there's probably a bug in your client or server code and it would help to post both.

Feel free to re-open if you find an issue after testing. Make sure to post your client and server code if you do. Please and thank you!

Sorry for delayed response.. The issue was with server code: I had an issue where the socket connection was not clearing from cache and so the player was mapped to the same socket connection multiple times. Thanks for the response :D