endel / NativeWebSocket

🔌 WebSocket client for Unity - with no external dependencies (WebGL, Native, Android, iOS, UWP)
Other
1.13k stars 155 forks source link

websocket.OnMessage never called in the demo (same in my project) #12

Closed jrmgx closed 4 years ago

jrmgx commented 4 years ago

Hello, first of all thank you for your work on this websocket implementation :) I have a question, and maybe a bug.

First I start the node server script in a terminal (on localhost) Then I start the demo scene from this repository (master branch) in unity mac 2019.3.7.f1

✅ The node server receive all the unity messages:

$ node index.js 
Listening on http://localhost:8080
client joined.
client sent a message: <Buffer 0a 14 1e>
client sent a message: plain text message
client sent a message: <Buffer 0a 14 1e>
client sent a message: plain text message
client sent a message: <Buffer 0a 14 1e>
client sent a message: plain text message
...

but on the Unity side I don't get the message from the server (as I understand in the code, the server is sending messages too) var id = setInterval(() => ws.send("hello world!"), 100); (note it should probably be 1000 instead of 100 but it's a detail

❌ In Unity console I only get:

Connection open!

and that's it.

Firewalls are off, everything is open.

I guess there is something wrong here? Any idea?

endel commented 4 years ago

Hi @jrmgx, if you downloaded the sources recently, are you using the Update() method described in the README?

  void Update()
  {
    #if !UNITY_WEBGL || UNITY_EDITOR
      websocket.DispatchMessageQueue();
    #endif
  }
nbentfeld commented 4 years ago

Hi @jrmgx, if you downloaded the sources recently, are you using the Update() method described in the README?

  void Update()
  {
    #if !UNITY_WEBGL || UNITY_EDITOR
      websocket.DispatchMessageQueue();
    #endif
  }

I just had the same issue after deleting that section. Readding it fixed it, so thanks!

endel commented 4 years ago

I just noticed the demo code was not updated to reflect the latest PR (#11). Going to close this. Let me know if you have any other issue!

jrmgx commented 4 years ago

As you already guessed I was using the demo code and the line was not here. I've added it and now it works. Thank you for your time! Have a great day