客户端如何连接到 MQL 中的服务器套接字?

发布于 2025-01-10 11:52:23 字数 235 浏览 1 评论 0原文

我想将超过 50000 个客户端连接到 MQL(Meta Trader)服务器套接字。 文档中没有对此进行描述: https://www.mql5.com/ en/docs/network/socketcreate

有多少客户端可以连接到服务器并且处理没有问题?

I want to connect more than 500 hundred client to the MQL (Meta Trader) server socket.
There is no description about it in the documentation: https://www.mql5.com/en/docs/network/socketcreate

How many client can connect to the sever and deal with no problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城之時有危險 2025-01-17 11:52:23

问:
“我想将超过 50000 个客户端连接到 MQL(Meta Trader)服务器...有多少客户端可以连接到服务器并处理没问题吗?”

答:
确实不是一件容易的事。

您可能已经知道,所有 MetaTrader 4/5 生态系统都是作为分布式系统构建的,具有终端端(在您的客户端端)和服务器 端(一个多主机平台,位于经纪商数据中心,负责注册用户、验证和馈送,除了许多其他值得注意的事情之外,还有一个对延迟敏感的高容量(市场容量乘以数量)活跃客户)流{ CFD | FX | * }-市场 QUOTE 消息(在 FX 市场上每毫秒轻松出现数百个 ToB 事件/消息)至所有已授权的活动 { MT4 | 终端计算机接受并执行来自授权客户端的 XTO 指令并报告结果(已执行的状态更改)客户资金会计操作)从 XTO-s 返回到相应交易者的终端)。在经纪商方面,这些工作量被分配给多台 MetaTrader 4/5 Server 服务器基础设施计算机。 Web 套接字处理由此类代理端基础设施的一部分提供服务。

MetaTrader 4/5 终端离您更近了,您可以在其中进行编程和操作。控制。即使在这里,资源量也是有限的,因为您可以从链接的终端端而不是可用编程工具的服务器端文档中读取:

您可以从一个 MQL5 程序创建最多 128 个套接字。如果超出限制,错误 5271 (ERR_NETSOCKET_TOO_MANY_OPENED) 将写入 _LastError

因此,Server 端由 Broker 控制(谁拥有使用 MetaQuotes, Inc. 产品的许可证,该产品已针对预期性能范围进行配置 - 是否准备好处理额外的 50.000 个 Web 套接字连接对于 NTO-s 可能不是经纪商的核心业务优先事项,因为他们向 XTO-s 收取费用)


"(...) 问题是,我们是否为每个客户端连接创建新的套接字?据我所知,我们仅在 Oninit 函数上创建服务器套接字一次,然后在计时器或图表事件处理程序,接受传入的客户端连接请求。所以,只有一个套接字,并且有许多客户端连接到该套接字,我说得对吗@user3666197? href="https://stackoverflow.com/users/478162/behzad">贝赫扎德 23小时前< /a>“


-&-

“我觉得我的问题不太清楚。我做过这个项目。我买了一个VPS,然后在上面安装了一个MT5,其中的EA起到了服务器的作用。服务器EA可以毫无问题地接受 500 个客户端。 对于客户端,在我的电脑上创建一个循环以将 500 个连接连接到服务器 EA – <一个href="https://stackoverflow.com/users/478162/behzad">贝赫扎德 4小时前< /a>“


鉴于您将 MT5 客户端终端称为某种意义上的“服务器”(只是一个 VPS 托管的 MT5 客户端终端,运行用户定义的 MQL5-ExpertAdviser 代码),似乎有一些魔力:

(A)
您声称能够“(...) 毫无问题地接受 500 个客户端。”,这与 MQL5 官方记录的从客户端打开的套接字不超过 128 个套接字的限制直接矛盾MQL5-{ EA | 脚本 }-code

脚本 }-代码(B)
官方 MQL5 文档没有提供 MT5 客户端终端如何运行 MQL5-{ EA | (B)
脚本 }-代码可以接收从远程客户端异步到达的连接(但没有指定这种情况如何发生,因为官方 MQL5 文档严格要求在 2022 年第一季度使用 MQL5 语言函数时实际上要避免这种情况发生)

< strong>(C)
官方 MQL5 文档确认,可以从 MT5 客户端终端内部进行 SocketConnect() MQL5-{ EA |将 }-code 编写到已知的 TCP/IP:PORT 地址:

string KNOWN_ADDRESS =    "some.known.FQDN";
int    KWOWN_PORT    =   80,
       TimeoutMILLIS = 1000;
bool   FLAG_ExtTLS   =     false;
//+------------------------------------------------------------------+
...
   int  MyOUTGOINGsocket  = SocketCreate(); //--- check the handle
   if ( MyOUTGOINGsocket != INVALID_HANDLE )
   {  
      if ( SocketConnect( MyOUTGOINGsocket, //--- from MT5-Terminal
                          KNOWN_ADDRESS,    //      to <_address_>
                          KNOWN_PORT,       //      on <_port_>
                          TimeoutMILLIS     //     try <_millis_>
                          )                 //    else FAIL
           )
      {
         Print( "INF: Established connection to ",
                 KNOWN_ADDRESS, ":",
                 KNOWN_PORT
                 );
         ...
         }
      else
      {
         Print( "ERR: Connection to ",
                 KNOWN_ADDRESS, ":",
                 KNOWN_PORT,
               " failed, error ",
                 GetLastError()
                 );
         ...
         }
      
      SocketClose( MyOUTGOINGsocket ); //--- close a socket to release RAM/resources
      }
   else
   {  Print( "ERR: Failed to even create a socket, error was ",
              GetLastError()
              );
      ...
      }
   ...
...
//+------------------------------------------------------------------+

肯定可以使用其他一些 DLL-#import-ed 工具来完成类似的任务,但没有 MCVE 制定的问题描述到目前为止,除了上面已经描述的事实之外,很难透露更多内容

Q :
" I want to connect more than 500 hundred client to the MQL (Meta Trader) server ... How many client can connect to the sever and deal with no problem? "

A :
Not an easy task, indeed.

As you may already know, all the MetaTrader 4/5 ecosystems are built as a distributed-system, having a Terminal-side ( on your, clients' side(s) ) and a Server-side ( a multi-host platform, located at the Broker DataCenter, who registers users, authenticates & feeds, besides many further noted things, a latency-sensitive, high-volume ( markets Volume-wise times number of active clients-wise ) stream of { CFD | FX | DeFi | * }-Market QUOTE messages (having easily cadence of hundreds ToB-events / messages per millisecond at FX-market) to all auth'ed active { MT4 | MT5 }-Terminal computers & accepts and executes XTO-instructions from auth'ed clients & reports results ( state-changes preformed & client's-funds accounting operations ) from XTO-s back to the respective trader's terminals ). That amount of work is, on the Broker side, split among several MetaTrader 4/5 Server server-infrastructure computers. The web-socket handling gets served by one part of such Broker-side infrastructure.

Closer to your reach goes the MetaTrader 4/5 Terminal, that you can program & control. Even here the amounts of resources are limited, as you can read from your linked, Terminal-side, not Server-side documentation of programming tools available :

You can create a maximum of 128 sockets from one MQL5 program. If the limit is exceeded, the error 5271 (ERR_NETSOCKET_TOO_MANY_OPENED) is written to _LastError.

So, the Server-side is controlled by the Broker ( who owns the license to use the MetaQuotes, Inc. product, that gets configured for expected performance envelopes - being ready or not to handle additional 50.000 web-socket connections for NTO-s might not be the Brokers' core business priority, as they collect fees from XTO-s )


"(...) The question is, do we create new socket for each client to connect? As I know, we create the server socket just one time on the Oninit function, then on a timer or chart event handler, do accepting incoming client connection request. So, there is just one socket and many client connect to this socket. Am I right @user3666197 ? – Behzad 23 hours ago"

-&-

"I think my question is not clear. I have done this project. I bought a VPS then install a MT5 on it with the EA that has played the server role. The sever EA could accept 500 client without any problem. It can send and receive messages as well as one connection. For clients, on my pc create a loop to connect 500 connection to the server. One socket on the server EA. – Behzad 4 hours ago"

Given you call MT5-Client-Terminal a "server" in a sense ( just a VPS-hosted MT5-Client-Terminal, running a user-defined MQL5-ExpertAdviser-code ), there seems to be some magic :

(A)
you claim to be able to "(...) accept 500 client without any problem.", which is in a direct contradiction to the official MQL5-documented limit of not more than 128 sockets ever opened from an MQL5-{ EA | Script }-code

(B)
the official MQL5-documentation does not present a way, how an MT5-Client-Terminal running an MQL5-{ EA | Script }-code can receive connections arriving asynchronously from remote clients ( yet without specifying how that might ever happen, as the official MQL5-Documentation is strict on practically avoiding such to happen if using the MQL5-language functions as of 2022-Q1 )

(C)
the official MQL5-documentation confirms, one can SocketConnect() from inside an MT5-Client-Terminal MQL5-{ EA | Script }-code to a known TCP/IP:PORT address :

string KNOWN_ADDRESS =    "some.known.FQDN";
int    KWOWN_PORT    =   80,
       TimeoutMILLIS = 1000;
bool   FLAG_ExtTLS   =     false;
//+------------------------------------------------------------------+
...
   int  MyOUTGOINGsocket  = SocketCreate(); //--- check the handle
   if ( MyOUTGOINGsocket != INVALID_HANDLE )
   {  
      if ( SocketConnect( MyOUTGOINGsocket, //--- from MT5-Terminal
                          KNOWN_ADDRESS,    //      to <_address_>
                          KNOWN_PORT,       //      on <_port_>
                          TimeoutMILLIS     //     try <_millis_>
                          )                 //    else FAIL
           )
      {
         Print( "INF: Established connection to ",
                 KNOWN_ADDRESS, ":",
                 KNOWN_PORT
                 );
         ...
         }
      else
      {
         Print( "ERR: Connection to ",
                 KNOWN_ADDRESS, ":",
                 KNOWN_PORT,
               " failed, error ",
                 GetLastError()
                 );
         ...
         }
      
      SocketClose( MyOUTGOINGsocket ); //--- close a socket to release RAM/resources
      }
   else
   {  Print( "ERR: Failed to even create a socket, error was ",
              GetLastError()
              );
      ...
      }
   ...
...
//+------------------------------------------------------------------+

One may use, for sure some other, DLL-#import-ed tools for the similar tasks, yet as no MCVE-formulated problem description was presented so far, it is so hard to tell anything more, except for the facts already described above

汹涌人海 2025-01-17 11:52:23

有一篇文章解释了如何在 MT5 上创建服务器:

在 MQL 中使用套接字,或如何成为信号提供者
https://www.mql5.com/en/articles/2599

There is an article explaining how to create a server on MT5:

Working with sockets in MQL, or How to become a signal provider
https://www.mql5.com/en/articles/2599

圈圈圆圆圈圈 2025-01-17 11:52:23

您可以通过 mql 客户端的 API 使用 webrequest 方法

You can using webrequest method with API from mql client

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文