Sockets and Websockets are two different things. You can however use MQL5 Sockets to write a websocket library of your own and it will work.
The existing limitation however, is that you have to grant web address access permission in the MetaTrader Options.
If however, I am misunderstanding your words, then please explain why you say that they are not suitable?
Sockets and Websockets are two different things. You can however use MQL5 Sockets to write a websocket library of your own and it will work.
The existing limitation however, is that you have to grant web address access permission in the MetaTrader Options.
If however, I am misunderstanding your words, then please explain why you say that they are not suitable?
LOL, I'm not sure if being the smartest qualifies to making MQL Socket work with Websocket Upgrade from HTTP, i've tried all possible to make it work in pure MQL, nothing works; if you need reference to past tries(some since years back), i can get a lot for you.
It just doesn't work for WSS, only the WS.
You may be completely depending on this article which is not made to work with wss, As Alain said, there are already products available in marketplace which are working with WSS without any external DLL, it means you have to write your own code, everything is fine with MQL and WSS. I doubt your affirmation too.
I eventually got it working with WSS, but mehn MQL Socket is complicated if one has to go by common sense or the book.
After checking myself, I confirm there is NO problem to have WebSockets, through TLS or without, working with MQL Socket.Ther
There is no problem when connecting through http:// or https:// but not working through ws:// or wss://. I tried to use WebsocketClient.mqh and Socket.mqh libraries. There are only inputs url, port but not http or ws configuration.
There is no problem when connecting through http:// or https:// but not working through ws:// or wss://. I tried to use WebsocketClient.mqh and Socket.mqh libraries. There are only inputs url, port but not http or ws configuration.
Have also problems to establish a secured connection to websocket server with the inbuild CWebSocketClient.
Here is the expert code:
#include<Websocket/WebSocketClient.mqh> CWebSocketClient wsc; string MyUrl="wss://echo.websocket.org";//"wss://127.0.0.1"; int MyPort=443;//9000; int MaxSize=256; bool UseTLS=true; bool connected=false; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { wsc.SetMaxSendSize(MaxSize); if( (connected=wsc.Connect(MyUrl,MyPort,5000,UseTLS,true))) { int sent=wsc.SendString("it works"); Print("sent data is "+IntegerToString(sent)); } else Print("connection failed"); EventSetMillisecondTimer(1000); return(INIT_SUCCEEDED); }
This connection always fails in function CWebSocketClient::upgrade.
When i use a node.js script, connection to
wss://echo.websocket.org
, then this works fine.
echo.websocket.org
is listed as webrequest address in MetaTrader. Otherwise, the connection would be blocked, which is not the case. So, i guess this is not the issue. it fails in ::upgrade at line:
if(StringFind(result,"Sec-WebSocket-Accept: "+sh1confirm)>=0))
Here is the node.js script that connects fine:
const WebSocket = require('ws'); // Create a WebSocket client const ws = new WebSocket('wss://echo.websocket.org', { rejectUnauthorized: true }); // Event listener for when the connection is established ws.on('open', function open() { console.log('Connected to the server'); // Send a message to the server ws.send('hi server'); }); // Event listener for incoming messages from the server ws.on('message', function incoming(data) { console.log('Received from server: %s', data); }); // Event listener for errors ws.on('error', function error(err) { console.error('Connection error: ', err); }); // Event listener for when the connection is closed ws.on('close', function close(code, reason) { console.log('Disconnected from the server'); console.log('Code: ', code); console.log('Reason: ', reason); });
Any help appreciated to get the CWebSocketClient client run in secure mode.
Thank you
You might want to read this https://www.mql5.com/en/book/advanced/project/project_websocket_mql5
Source code is here:
https://www.mql5.com/en/code/45593

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm not sure if MQL know their Socket TLS functions aren't suitable for Websocket, i've been spending all time of my every last 5 days searching this forum, that forum and all forum on how to make WSS Websocket work all to no avail.
Should one just go to WinAPI for every little function?