Cannot read data from websocket connection

 

Hi,

When I call SocketTlsRead() function it returns -1 and the error code is 5273 and it terminates the websocket connection. I would appreciate any ideas on how to solve this problem.

int OnInit(){
    socket = SocketCreate(SOCKET_DEFAULT);
    if (socket != INVALID_HANDLE){
        if (SocketConnect(socket, host, port, timeout)){
            Print("Socket Connected");
        }else{
            Print("Cannot Connect Socket");
            return (INIT_FAILED);
        }
    }
    EventSetTimer(3);
    return(INIT_SUCCEEDED);
}

void OnTimer(){
    if (SocketIsConnected(socket)){
        string result;
        uint len = SocketIsReadable(socket);
        if (len > 0){
            uchar response[];
            int res_len = SocketTlsRead(socket, response, len);
            if (res_len > 0){
                result = CharArrayToString(response);
                Print(result);
            }
        }
    }else{
        Print("Socket disconnected");
    }
}
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

I do not have an idea what the problem can be but usually it is best to do the code as similar as possible to what you have in the documentation. Any deviation from what you see in the documentation example code could cause problem.

https://www.mql5.com/en/docs/network/sockettlsread

Documentation on MQL5: Network Functions / SocketTlsRead
Documentation on MQL5: Network Functions / SocketTlsRead
  • www.mql5.com
Read data from secure TLS connection. Parameters socket [in]  Socket handle returned by the SocketCreate function. When an incorrect handle is...