Skip to content

SimpleNamedPipe is a lightweight C++ library for creating and managing asynchronous named pipe servers on Windows.

License

Notifications You must be signed in to change notification settings

NewYaroslav/SimpleNamedPipe

Repository files navigation

SimpleNamedPipe

Logo

SimpleNamedPipe is a lightweight C++ library for creating and managing asynchronous named pipe servers on Windows.

The project is distributed under the MIT license. See the LICENSE file for the full text.

For the documentation in Russian, see README-RU.md.

Features

  • asynchronous client handling through IO Completion Port;
  • runs either in a separate thread or blocking the current one (the start() parameter);
  • supports up to 256 simultaneous clients;
  • send queue with limits on message size and count;
  • event notifications via callbacks or the ServerEventHandler class;
  • lightweight MQL5 client with optional global callbacks;
  • the MQL5 client performs read/write synchronously; call update() for polling (e.g., in a timer).

Quick Start

Minimal server

#include "SimpleNamedPipe/NamedPipeServer.hpp"
using namespace SimpleNamedPipe;

int main() {
    NamedPipeServer server({"ExamplePipe"});

    server.on_message = [&server](int id, const std::string& msg) {
        server.send_to(id, "Echo: " + msg);
    };

    server.start(); // launches the server in a separate thread
    std::cin.get(); // waits for Enter
    server.stop();
}

Minimal MQL5 client

#include <SimpleNamedPipe\NamedPipeClient.mqh>

NamedPipeClient pipe;

int OnInit() {
    pipe.open("ExamplePipe");
    EventSetMillisecondTimer(10);
    return INIT_SUCCEEDED;
}

void OnDeinit(const int reason) {
    EventKillTimer();
}

void OnTimer() {
    pipe.update();
    if(pipe.connected())
        pipe.write("ping");
}

Installation

  1. Install CMake and a compiler (Visual Studio or MinGW).
  2. Run build_all.bat (or build_all_mingw.bat for MinGW) to build the library and examples.
  3. The install_mql5.bat script copies files from the MQL5 directory to all detected MetaTrader 5 terminals.

Examples

Example sources reside in the examples directory.

  • callback_example.cpp shows using separate callbacks (on_connected, on_message, etc.).
  • universal_event_example.cpp demonstrates similar logic with a single on_event handler.

Useful links

License

SimpleNamedPipe is released under the MIT license. See LICENSE for details.