39 lines
1.5 KiB
MQL5
39 lines
1.5 KiB
MQL5
//+------------------------------------------------------------------+
| |||
//| SocketDiag.mq5 — diagnostic: test MQL5 outbound sockets |
| |||
//+------------------------------------------------------------------+
| |||
#property strict
| |||
| |||
void TestConnect(const string host, const int port)
| |||
{
| |||
PrintFormat("[SocketDiag] === test %s:%d ===", host, port);
| |||
ResetLastError();
| |||
int s = SocketCreate();
| |||
PrintFormat("[SocketDiag] SocketCreate -> handle=%d GetLastError=%d", s, GetLastError());
| |||
if(s == INVALID_HANDLE || s == 0)
| |||
return;
| |||
ResetLastError();
| |||
bool ok = SocketConnect(s, host, port, 3000);
| |||
PrintFormat("[SocketDiag] SocketConnect(%s,%d,3000) -> %s | GetLastError=%d",
| |||
host, port, (ok ? "TRUE" : "FALSE"), GetLastError());
| |||
PrintFormat("[SocketDiag] SocketIsConnected -> %s",
| |||
(SocketIsConnected(s) ? "TRUE" : "FALSE"));
| |||
if(ok)
| |||
{
| |||
string msg = "{\"action_type\":\"Heartbeat\",\"symbol\":\"MQL5_DIAG\"}\r\n";
| |||
uchar buf[];
| |||
int n = StringToCharArray(msg, buf, 0, WHOLE_ARRAY, CP_UTF8) - 1;
| |||
ResetLastError();
| |||
int sent = SocketSend(s, buf, n);
| |||
PrintFormat("[SocketDiag] SocketSend -> %d bytes | GetLastError=%d", sent, GetLastError());
| |||
}
| |||
SocketClose(s);
| |||
Print("[SocketDiag] === done ===");
| |||
}
| |||
| |||
void OnStart()
| |||
{
| |||
Print("[SocketDiag] MQL5 outbound socket diagnostics");
| |||
TestConnect("127.0.0.1", 5555); // Centaur router (listening)
| |||
TestConnect("127.0.0.1", 22346); // MCP server (listening)
| |||
TestConnect("127.0.0.1", 59999); // closed port (comparison)
| |||
}
|