以下是我尝试通过MQL5作为客户端连接套接字,但服务器来自Python的情况。请参阅以下内容:
Server.py
import socket
def actual_work():
return 'dummy_reply'
def main():
sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
try:
sock.bind( ('127.0.0.1', 6666) )
while True:
data, addr = sock.recvfrom( 4096 )
reply = actual_work()
sock.sendto(reply, addr)
except KeyboardInterrupt:
pass
finally:
sock.close()
if __name__ == '__main__':
main()
MQL5的客户端
#include <simple-client-socket-send-only.mqh>
ClientSocket * glbSocket;
void OnInit()
{
glbSocket = new ClientSocket("127.0.0.1", 6666);
if (!glbSocket.IsSocketConnected()) {
Print("Failed to connect");
}
}
void OnDeinit(const int reason)
{
delete glbSocket;
}
void OnTick()
{
if (glbSocket.IsSocketConnected()) {
Print(glbSocket.Send("Hello"));
}
}
包含的库在这里:Socket client MQH
我无法使用此格式连接到套接字。如果我缺少某些东西,请告诉我。帮我改善。