• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: Javascript sending only one message over websocket in browser

Resolved: Javascript sending only one message over websocket in browser

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have a websocketserver running on a ESP32 which works perfect.
My problem is that if I send a message to the server over a website the socketserver on the ESP32 executes the .send(message) only the first time and is not sending anymore any message.
If I send a message from the developertools/console in chrome it works every time.
At this point I suppose my problem seems not to be on the server-side but on the client-side.
This is my html/javascript-code running inside chrome:
In my console logs I can see that it enters the “isKeyPressed” if-statement but it is not executing the “websocket.onopen = function (event)”.
What am I doing wrong?

Answer:

websocket.onopen is only triggered the first time the socket is open. Since it’s already open at this point, you should be able to just directly call the send function.
In other words:
becomes:

If you have better answer, please add a comment about this, thank you!

arduino-esp32 esp32 html javascript websocket
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Reshape tensors of unknown shape with tf.function

26/03/2023

Resolved: Use Svelte Component as Slot

26/03/2023

Resolved: Vaadin 14.9 – Redirect on Session Destroy Event

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.