Discussion of article "Websockets for MetaTrader 5" - page 2

 
https://www.mql5.com/en/book

you can find working native websocket in the book

enjoy
 
Soewono Effendi #:
https://www.mql5.com/en/book

you can find working native websocket in the book

enjoy

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.

 
Shane Leigh Kingston #:

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 ;)

 
Shane Leigh Kingston #:

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.

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.

Thanks in advance 
 
pauldic #:
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:

MQL5 Book: Advanced language tools / Projects / WebSocket protocol in MQL5
MQL5 Book: Advanced language tools / Projects / WebSocket protocol in MQL5
  • www.mql5.com
We have previously looked at Theoretical foundations of the WebSockets protocol . The complete specification is quite extensive, and a detailed...
 
Stanislav Korotky #:

There is another implementation of websockets in the algotrading book.

You may find actual version of source codes in the discussion on the forum:


Yes @Stanislav I later found it yesterday and it has been useful thus far, thank you