0

I’m developing an MQL5 Expert Advisor that should connect to a local TCP server (127.0.0.1:5001). The server is running and responds correctly to Telnet. In MetaTrader, I added 127.0.0.1:5001 in Options → Expert Advisors → Allow WebRequest for listed URLs. Firewall is disabled, and the port is free.

My MQL5 code is:

int socket;

int OnInit()
{
    socket = SocketCreate();
    if(socket == INVALID_HANDLE)
    {
        Print("SocketCreate failed");
        return(INIT_FAILED);
    }

    if(!SocketConnect(socket, "127.0.0.1", 5001))
    {
        Print("SocketConnect failed with error: ", GetLastError());
        return(INIT_FAILED);
    }

    Print("Connected successfully");
    return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
    SocketClose(socket);
}

Tests I have done:

  • Verified the server is listening and reachable with Telnet.
  • Confirmed the port (5001) is open and available.
  • Disabled firewall completely.
  • Used numeric IP 127.0.0.1.
  • Added 127.0.0.1:5001 to Metatrader Expert Advisors options.
  • Tried creating a TCP server using Netcat (nc -l 5001), but MQL5 still fails with error 4014.

Question Has anyone implemented a minimal TCP server for MQL5 testing or has a working configuration example? I want to understand whether the issue is on the MQL5 side or the server side. Any example code or demo would be greatly appreciated.

2
  • try localhost instead of 127.0.0.1:5001 in the list of allowed web urls Commented Oct 9 at 18:13
  • for websocket you must use 127.0.0.1:5001 , but for simply socket you must use only 127.0.0.1 now work thanks at all Commented Oct 10 at 6:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.