MQL5 SocketConnect fails with error 4014 connecting to local TCP server
MQL5 SocketConnect fails with error 4014 connecting to local TCP server
Loading saved threads...
franzisko · External communityPost link
External question — Stack Overflow Stack Exchange
Author: franzisko
Original post: https://stackoverflow.com/questions/79786669
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
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.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: franzisko Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/79786669 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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.
Checking account access…