the same issue
did you find a solution?
Dunno if this is still relevant for anyone after so many years but I was also just struggeling with this... For me it worked when I used SocketIsReadable(..) first and then used the returned number of bytes as max size for the buffer in SocketRead(..)
Sample Code:
static int socket = INVALID_HANDLE; if(socket == INVALID_HANDLE) socket = SocketCreate(); if(!SocketIsConnected(socket) && SocketConnect(socket,SERVER,PORT,1000)){ Print(__FUNCTION__," > Connected to server socket (",SERVER,":",PORT,")"); } if(SocketIsConnected(socket)){ int len = 0; while((len = SocketIsReadable(socket)) > 0){ uchar buffer[]; int res = SocketRead(socket,buffer,len,1000); if(res > -1){ string txt = CharArrayToString(buffer,0,WHOLE_ARRAY,CP_UTF8); static string bufferStr; bufferStr += CharArrayToString(buffer); } } }
Do not ask me why it works. I have no clue but maybe it helps someone.
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
I'm consistently receiving error 5273 when invoking SocketRead MQL5 API.
I connect to the server from an MT terminal and would like to check periodically if some data have arrived from the server. Here is my code:
It works just fine when I connect to the very same server and send/receive data if I replace MT5 built-in socket with winsocket. However using winsocket will not allow me to publish the EA on market which is not an option for me.
Sending data works just fine and server receives the data correctly. I also checked that the server sends packets to the connected MT terminal correctly.
Any ideas?