Discussing the article: "Market Simulation: (Part 11): Sockets (V)"

 

Check out the new article: Market Simulation: (Part 11): Sockets (V).

We are beginning to implement the connection between Excel and MetaTrader 5, but first we need to understand some key points. This way, you won't have to rack your brains trying to figure out why something works or doesn't. And before you frown at the prospect of integrating Python and Excel, let's see how we can (to some extent) control MetaTrader 5 through Excel using xlwings. What we demonstrate here will primarily focus on educational objectives. However, don't think that we can only do what will be covered here.

Now recall that the mini-chat server uses port 27015, and the echo server — which will run via Excel — also uses the same port. Therefore, theoretically, we have a conflict of interest here. One might assume the operating system would not allow a server to interfere or attempt to listen on the same port using the same protocol. In this case, we are using the TCP protocol. However, we could use TCP on one server and UDP on the other. In that scenario, there would be no issue using the same port.

But when we use the same port, the same protocol, and the same host, things get a bit more complicated.

I want to emphasize this point so that those aiming to become advanced users of sockets understand that working with them requires certain precautions. I want you — before you see how the communication between Excel and MetaTrader 5 is actually implemented — to understand what happens when two different servers use the same resources. In this case: the same protocol, the same port, and the same host. To grasp this, first open the mini-chat server and let it wait for a connection.

Now open the echo server in Excel and leave it waiting for a connection as well. That is, we’ll have something resembling this:


Author: Daniel Jose