客户端套接字无法将MQL5与Python Server连接

时间:2018-08-07 09:10:24

标签: python python-3.x sockets mql5

以下是我尝试通过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

我无法使用此格式连接到套接字。如果我缺少某些东西,请告诉我。帮我改善。

0 个答案:

没有答案