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

 
Denis Kirichenko # :

So the promised 3 years are waiting... there is very little left - a year to wait )))

Probably :)))

 
MetaQuotes:

New article Websockets for MetaTrader 5 has been published:

Author: Francis Dube

Great! So how do you parse the continuation frame? So far it only parses frames that is in the first response. I’m using nodejs websocket.
 

Hi great work there @Francis Dube

I have implemented your library to work with my web socket server in nodejs/nestjs. The issue i'm facing is that when i'm using the sockets locally with my server, everything works fine. mql5 socket send the handshake i get the correct response i.e. "101 Switching protocols". 

But the things changes as soon as i deploy my nestjs app to digitalocean app-platform, Initially i was not able to connect mql5 sockets to my server but then i was able to connect to it but i'm not getting correct response for handshake due to which the connect method from "CWebsocketClient" returns false as upgrade method didn't get to parse any response, I only get "H" as the response from my deployed app.

though i'm not sure about the rest of the functionality as the socket status consistently set to "CONNECTING" i'm not able to do anything after the successful connection. However, when after calling the connect method if send the data to my server using "sendString" method the data get delivered. 

And thats where i'm confused on how to implement things in my app, as i'm not able to test thing handshake thing any other way, i have tried extensions to check if my web socket is working in my app turns out its working fine, but as soon as it comes to mql5 things are messed up and not entirely elaborative enough to get the cause of this behaviour.

Any leads or guidance on this issue will be very much appreciated.

PS: I'm not doing any fancy stuff for now in my mql5 EA, i'm just following the connection guide in the article and just connecting with the server. Nothing else! :(

 

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.

 
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