
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
https://www.mql5.com/en/book
I think you might be confusing websockets with regular networking sockets or plain HTTP WebRequests. Websockets require custom coding on top of regular HTTP requests. I managed to get a solution working based on this article with some project specific modifications.
I think you might be confusing websockets with regular networking sockets or plain HTTP WebRequests. Websockets require custom coding on top of regular HTTP requests. I managed to get a solution working based on this article with some project specific modifications.
gave you a hint,
if you do not want to look in the book, it's your loss not mine ;)
Note there is a bug in WebsocketClient.fillRxBuffer, in the scenario where there are multiple calls to m_socket.Read(..) within the while loop.
m_socket.Read(..) is not appending data to the end of the array, but rather it writes to the start of the array.
In my case, where I was connecting to a local web socket for testing, I found the first call to m_socket.Read(..) was fetching a single byte only, then a second loop to m_socket.Read(..) was fetching the rest. As a result, the buffer was missing the first byte, which caused an error when parsing the frame.
You also need to ensure the m_rxbuf is empty prior to filling the buffer, or it may think more data has been fetched then it actually has. The buffer is cleared out after parsing frames, but just to be sure, I decided to clear it out whenever calling fillRxBuffer.
I also made the m_socket.Read(..) stop looping once there is no more data to read, so it doesn't keep waiting for the timeout period. Ideally I think it should actually keep reading until there is enough data to parse a frame, but that requires restructuring the code a bit.
Thanks for this article though. So far its the closest solution I have found to what I was looking for. Eventually I may create my own web socket library.
Thanks in advance
Please @ Shane Leigh Kingston, I knew this is an old post but need a way to implement websocket with mql5 and this library seems to be the only relatively close to it. But again am face the issue you just described but am not an expert in this area. Please can you guide me on how to make this work. I will be high grateful if you could help.
There is another implementation of websockets in the algotrading book.
You may find actual version of source codes in the discussion on the forum:
Forum on trading, automated trading systems and testing trading strategies
Experts: MQL5 Programming for Traders – Source Codes from the Book. Part 7
Stanislav Korotky, 2025.03.10 13:32
I'm attaching some bugfixes and improvements in the websockets classes.There is another implementation of websockets in the algotrading book.
You may find actual version of source codes in the discussion on the forum: