Add library contents and a nice README
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| TestZmq.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>
|
||||
//+------------------------------------------------------------------+
|
||||
//| Script program start function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnStart()
|
||||
{
|
||||
//--- Test capabilities
|
||||
Print(">>> Testing capabilities");
|
||||
Print("0) Zmq version is [",Zmq::getVersion(),"]");
|
||||
Print("1) Supports ipc:// protocol: [",Zmq::hasIpc(),"]");
|
||||
Print("2) Supports pgm:// protocol: [",Zmq::hasPgm(),"]");
|
||||
Print("3) Supports norm:// protocol: [",Zmq::hasNorm(),"]");
|
||||
Print("4) Supports tipc:// protocol: [",Zmq::hasTipc(),"]");
|
||||
Print("5) Supports curve security: [",Zmq::hasCurve(),"]");
|
||||
Print("6) Supports gssapi security: [",Zmq::hasGssApi(),"]");
|
||||
Print(">>> End testing capabilities");
|
||||
|
||||
//--- Test Z85 encoding/decoding
|
||||
Print(">>> Testing Z85 encoding/decoding");
|
||||
|
||||
string data="12345678";
|
||||
Print("1) Original data is: ",data);
|
||||
|
||||
string secret=Z85::encode(data);
|
||||
Print("2) Encrypted value is: ",secret);
|
||||
|
||||
string decoded=Z85::decode(secret);
|
||||
Print("3) Decoded: ",decoded);
|
||||
Print("4) Decoded value is equal to original: [",decoded==data,"]");
|
||||
Print(">>> End testing Z85 encoding/decoding");
|
||||
|
||||
//--- Test atomic counters
|
||||
Print(">>> Testing atomic counters");
|
||||
AtomicCounter counter;
|
||||
Print("1) Initial value should be 0: [",counter.get()==0,"]");
|
||||
counter.set(5);
|
||||
Print("2) Counter set to 5: [",counter.get()==5,"]");
|
||||
counter.increase();
|
||||
Print("3) Increased value should be 6: [",counter.get()==6,"]");
|
||||
counter.decrease();
|
||||
Print("4) Decreased value should be 5: [",counter.get()==5,"]");
|
||||
Print(">>> End testing atomic counters");
|
||||
|
||||
//--- Test context
|
||||
Print(">>> Testing context");
|
||||
Context context;
|
||||
Print("1) Default IO threads should be ZMQ_IO_THREADS_DFLT: [",context.getIoThreads()==ZMQ_IO_THREADS_DFLT,"]");
|
||||
Print(">>> trying to set io threads to 2");
|
||||
context.setIoThreads(2);
|
||||
Print("2) Now IO threads should be 2: [",context.getIoThreads()==2,"]");
|
||||
Print("3) Socket limit: [",context.getSocketLimit(),"]");
|
||||
Print("4) Max sockets: [",context.getMaxSockets(),"]");
|
||||
Print("5) Max message size: [",context.getMaxMessageSize(),"]");
|
||||
Print(">>> End testing context");
|
||||
|
||||
Socket s(context,ZMQ_REP);
|
||||
string addr="inproc://abc";
|
||||
if(!s.bind(addr))
|
||||
{
|
||||
Debug(StringFormat("Error binding %s: %s",addr,Zmq::errorMessage()));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(StringFormat("Success binded %s",addr));
|
||||
}
|
||||
string endpoint;
|
||||
s.getLastEndpoint(endpoint);
|
||||
Print("Last endpoint is: [",endpoint,"]");
|
||||
|
||||
string principal;
|
||||
s.getGssApiPrincipal(principal);
|
||||
Print("Principal is [",principal,"]");
|
||||
|
||||
//--- Test curve
|
||||
Print(">>> Testing curve");
|
||||
string genpub,gensec;
|
||||
Z85::generateKeyPair(genpub,gensec);
|
||||
Print("1) Generated public key: [",genpub,"]");
|
||||
Print("1) Generated private key: [",gensec,"]");
|
||||
Print("2) Derive public key from secret key: [",Z85::derivePublic(gensec)==genpub,"]");
|
||||
Print(">>> End testing curve");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,42 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| HelloWorldServer.mq5 |
|
||||
//| Copyright 2016, Li Ding |
|
||||
//| dingmaotu@hotmail.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2016, Li Ding"
|
||||
#property link "dingmaotu@hotmail.com"
|
||||
#property version "1.00"
|
||||
|
||||
#include <Zmq/Zmq.mqh>
|
||||
//+------------------------------------------------------------------+
|
||||
//| Hello World server in MQL |
|
||||
//| Binds REP socket to tcp://*:5555 |
|
||||
//| Expects "Hello" from client, replies with "World" |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnStart()
|
||||
{
|
||||
Context context;
|
||||
Socket socket(context,ZMQ_REP);
|
||||
|
||||
socket.bind("tcp://*:5555");
|
||||
|
||||
while(true)
|
||||
{
|
||||
ZmqMsg request;
|
||||
|
||||
// Wait for next request from client
|
||||
|
||||
// MetaTrader note: this will block the script thread
|
||||
// and if you try to terminate this script, MetaTrader
|
||||
// will hang (and crash if you force closing it)
|
||||
socket.recv(request);
|
||||
Print("Receive Hello");
|
||||
|
||||
Sleep(1000);
|
||||
|
||||
ZmqMsg reply("World");
|
||||
// Send reply back to client
|
||||
socket.send(reply);
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user