Recent

Author Topic: Using WebSockets with Lazarus-2.0.12-fpc-3.2.0-win32  (Read 8144 times)

Warfley

  • Sr. Member
  • ****
  • Posts: 451
Re: Using WebSockets with Lazarus-2.0.12-fpc-3.2.0-win32
« Reply #30 on: April 14, 2021, 04:12:16 pm »
For my need, I can also send Pong without it being requested. I just need to learn how to do it.
This to prevent the broadcaster from closing the connection, thinking that it is not in use anymore.
Unsolicited pong messages are ignored according to the websocket standard. You don't need to handle them yourself, when the RecieveMessage function recieves a ping, it will automatically answer with a pong. So as long as you keep receiving, it is taken care of.
Also. One last question.
Regarding speed.
How much data/text should I be able to receive per second through this solution? Is it possible to make an estimate here, or is this completely dependent on the Internet-connection and computer hardware?
Can depend on both, but usually your network connection is the limiting factor. But of course, if you have a high CPU usage, a very old motherboard or a very fast network connection, it could be that your network delives the data faster then the thread can read it. But generally speaking it should be as fast as your usual download speed. (Unless the server has a limit in, or is under heavy load, you can of course not receive faster than the server is sending)

MortenB

  • Jr. Member
  • **
  • Posts: 59
Re: Using WebSockets with Lazarus-2.0.12-fpc-3.2.0-win32
« Reply #31 on: April 14, 2021, 06:22:20 pm »
Great.
Thank you for your answers.
In regards to the Pong, I don't know much about the websocket standards, but I have seen that Binance recommends one being sent every half hour or so in order to ensure connection not being broken.
They also say that unsolicited are allowed.
Well. Since you say it is automatically taken care of, I will not give that another thought.
In fact, sometimes the connection runs for 1 hour, sometimes it runs for 18 hours. My only problem so far is to detect when it breaks so that I can restart it, and this must be done before I start decoding the received string of data.
At the moment, my decoder just crashes when the connection is lost, something I expect is because the received string begins to contain garbage at the end. :p
-
Is there a simple call I can do to check if the connection is working properly, or should I make a check on the received string to make sure it is Ok? Maybe just check the length, and if the length is kind of Ok, then check the end of the string.  If it ends like a JSON-text, then OK, and discard string and restart connection if the end of the text is weird.

 

TinyPortal © 2005-2018