dfc*_*sdf 1 python sockets mql mql5
我正在尝试使用套接字在 MetaTrader 5 和 Python 之间建立连接。服务器部分用 python 编写,客户端部分用 mql5 编写。客户也是 Expert Advisor,而不是指标。问题是当我同时运行服务器和客户端时,客户端给我“错误4014”。如果有人能帮助我解决这个问题,我非常感激。
//this is python server code
import socket
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serv.bind(('127.0.0.1', 9090))
serv.listen(1)
while True:
conn, addr = serv.accept()
print('client connected to :', addr)
conn.close()
//This is mql5 client code
//+------------------------------------------------------------------+
//| test_client_EA.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
int socket;
int OnInit()
{
socket=SocketCreate();
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
SocketClose(socket);
}
void OnTick()
{
socket=SocketCreate();
if(socket!=INVALID_HANDLE)
{
if(SocketConnect(socket,"127.0.0.1",9090,1000))
{
Print("Connected to "," 127.0.0.1",":",9090);
}
else
{
Print("Connection ","127.0.0.1",":",9090," error ",GetLastError());
}
SocketClose(socket);
}
else Print("Socket creation error ",GetLastError());
}
Run Code Online (Sandbox Code Playgroud)
小智 6
您是否尝试过在选项中配置 WebRequest 设置?
配置的路径是工具 -> 选项 -> Expert Advisors -> WbRequest(复选框)。您想要添加 localhost 或 127.0.0.1 以允许连接。
我希望这仍然悬而未决并且有帮助。
最好的
| 归档时间: |
|
| 查看次数: |
3764 次 |
| 最近记录: |