Sockets, new to this, can't make it recieve data. whats wrong?
//+------------------------------------------------------------------+ //| Función para enviar y recibir datos | //+------------------------------------------------------------------+ string CommunicateWithPython(string data) { int socket_handle = InitSocket(); if(socket_handle < 0) return ""; uchar send_buffer[]; StringToCharArray(data, send_buffer); int bytesSent = SocketSend(socket_handle, send_buffer, ArraySize(send_buffer)); if(bytesSent < 0) { Print("Error sending data!"); SocketClose(socket_handle); return ""; } Print("data sent: ", bytesSent); uint timeout = 5000; // 5 segundos de tiempo de espera uchar rsp[]; string result; uint timeout_check=GetTickCount()+timeout; //--- read data from sockets till they are still present but not longer than timeout do { uint len=SocketIsReadable(socket_handle); if(len) { int rsp_len; //--- various reading commands depending on whether the connection is secure or not rsp_len=SocketRead(socket_handle,rsp,len,timeout); //--- analyze the response if(rsp_len>0) { result+=CharArrayToString(rsp,0,rsp_len); } } } while(GetTickCount()<timeout_check && !IsStopped()); SocketClose(socket_handle); if(result == "") { Print("no data from pthogn"); return ""; } Print("data from python received: ", result); return result; }
Yashar Seyyedin #:
string CommunicateWithPython(string data) { int socket_handle = InitSocket(); if(socket_handle < 0) return ""; uchar send_buffer[]; StringToCharArray(data, send_buffer); int bytesSent = SocketSend(socket_handle, send_buffer, ArraySize(send_buffer)); if(bytesSent < 0) { Print("Error sending data!"); SocketClose(socket_handle); return ""; } Print("data sent: ", bytesSent); uint timeout = 5000; // 5 segundos de tiempo de espera uchar rsp[]; string result; uint timeout_check=GetTickCount()+timeout; //--- read data from sockets till they are still present but not longer than timeout do { uint len=SocketIsReadable(socket_handle); if(len) { int rsp_len; //--- various reading commands depending on whether the connection is secure or not rsp_len=SocketRead(socket_handle,rsp,len,timeout); //--- analyze the response if(rsp_len>0) { result+=CharArrayToString(rsp,0,rsp_len); } } } while(GetTickCount()<timeout_check && !IsStopped()); SocketClose(socket_handle); if(result == "") { Print("no data from pthogn"); return ""; } Print("data from python received: ", result); return result; }
string CommunicateWithPython(string data) { int socket_handle = InitSocket(); if(socket_handle < 0) return ""; uchar send_buffer[]; StringToCharArray(data, send_buffer); int bytesSent = SocketSend(socket_handle, send_buffer, ArraySize(send_buffer)); if(bytesSent < 0) { Print("Error sending data!"); SocketClose(socket_handle); return ""; } Print("data sent: ", bytesSent); uint timeout = 5000; // 5 segundos de tiempo de espera uchar rsp[]; string result; uint timeout_check=GetTickCount()+timeout; //--- read data from sockets till they are still present but not longer than timeout do { uint len=SocketIsReadable(socket_handle); if(len) { int rsp_len; //--- various reading commands depending on whether the connection is secure or not rsp_len=SocketRead(socket_handle,rsp,len,timeout); //--- analyze the response if(rsp_len>0) { result+=CharArrayToString(rsp,0,rsp_len); } } } while(GetTickCount()<timeout_check && !IsStopped()); SocketClose(socket_handle); if(result == "") { Print("no data from pthogn"); return ""; } Print("data from python received: ", result); return result; }
Thanks! you made me not loose more time.
this is the MQL5 code I use:
and this is the py script server.py
Please, I'm new to Sockets, can some one tell me what's wrong and how to make it work?