dingmaotu / mql-zmq

ZMQ binding for the MQL language (both 32bit MT4 and 64bit MT5)
Apache License 2.0
543 stars 298 forks source link

Late binding of type #65

Closed biohazardxxx closed 1 month ago

biohazardxxx commented 7 months ago

Is it somehow possible to do a late binding of socket? For example when having server and client code in one expert. As example this does not work:

Context context("myContext");
Socket socket(context,ZMQ_REQ);
void OnInit(){
      if(isServer)
            socket = Socket(context,ZMQ_REP);
...
}
dingmaotu commented 6 months ago

Maybe you can use a global pointer to store the socket?

biohazardxxx commented 6 months ago

Yes sure but if I want to decide on the type of socket based on EA settings (isServer) it requires late binding :-)

dingmaotu commented 6 months ago

I think I didn't make myself clear.

Context context("myContext");
Socket *socket;
void OnInit(){
      if(isServer)
            socket = new Socket(context,ZMQ_REP);
            // server init
      else
           // client init
...
}

This way, you can create either a server or client based on EA settings.