From c8ffea4433da789ba7142e9c8ca692f98e6ee47b Mon Sep 17 00:00:00 2001 From: Ding Li Date: Wed, 28 Dec 2016 13:16:59 +0800 Subject: [PATCH] Add an usage sample to README --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index 141fe29..1c2582a 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,43 @@ MQL strings are Win32 UNICODE strings (basically 2-byte UTF-16). In this binding You can find a simple test script in `Scripts/Test`, and you can find examples of the official guide in Scripts/ZeroMQGuideExamples. I intend to translate all examples to this binding, but now only the hello world example is provided. I will gradually add those examples. Of course forking this binding if you are interested and welcome to send pull requests. +Here is a sample from `HelloWorldServer.mq4`: + +```c++ +#include +//+------------------------------------------------------------------+ +//| 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); + } + } +``` + ## TODO 1. Write more tests.