Sharing context between mql programs in the same Terminal; add new examples
This commit is contained in:
Binary file not shown.
@@ -15,12 +15,12 @@
|
||||
//+------------------------------------------------------------------+
|
||||
void OnStart()
|
||||
{
|
||||
Context context;
|
||||
Context context("helloworld");
|
||||
Socket socket(context,ZMQ_REP);
|
||||
|
||||
socket.bind("tcp://*:5555");
|
||||
|
||||
while(true)
|
||||
while(!IsStopped())
|
||||
{
|
||||
ZmqMsg request;
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| VersionReporting.mq4.mq4 |
|
||||
//| Copyright 2016, Li Ding |
|
||||
//| dingmaotu@hotmail.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2016, Li Ding"
|
||||
#property link "dingmaotu@hotmail.com"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
#include <Zmq/Zmq.mqh>
|
||||
//+------------------------------------------------------------------+
|
||||
//| Report 0MQ version |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnStart()
|
||||
{
|
||||
Print(Zmq::getVersion());
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,54 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| WeatherUpdateServer.mq4.mq4 |
|
||||
//| Copyright 2016, Li Ding |
|
||||
//| dingmaotu@hotmail.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2016, Li Ding"
|
||||
#property link "dingmaotu@hotmail.com"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
#include <Zmq/Zmq.mqh>
|
||||
|
||||
#define within(num) (int) ((float) num * MathRand() / (32767 + 1.0))
|
||||
//+------------------------------------------------------------------+
|
||||
//| Weather update server in MQL |
|
||||
//| Binds PUB socket to tcp://*:5556 |
|
||||
//| Publishes random weather updates |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnStart()
|
||||
{
|
||||
//--- Prepare our context and publisher
|
||||
Context context;
|
||||
Socket publisher(context,ZMQ_PUB);
|
||||
publisher.bind("tcp://*:5556");
|
||||
|
||||
long messages_sent=0;
|
||||
//--- Initialize random number generator
|
||||
MathSrand(GetTickCount());
|
||||
while(!IsStopped())
|
||||
{
|
||||
int zipcode,temperature,relhumidity;
|
||||
|
||||
// Get values that will fool the boss
|
||||
|
||||
// MetaTrader Note:
|
||||
// if RAND_MAX < 100000, which is the case for MetaTrader,
|
||||
// you may never get the required value
|
||||
// So 30000 might be a good alternative
|
||||
zipcode=within(30000);
|
||||
temperature=within(215) - 80;
|
||||
relhumidity=within(50) + 10;
|
||||
|
||||
// Send message to all subscribers
|
||||
ZmqMsg message(StringFormat("%05d %d %d",zipcode,temperature,relhumidity));
|
||||
publisher.send(message);
|
||||
messages_sent++;
|
||||
|
||||
if(messages_sent%1000000==0)
|
||||
{
|
||||
PrintFormat("Sent %dM messages now.",messages_sent/1000000);
|
||||
}
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user