{"id":19534910,"url":"https://github.com/newyaroslav/simple-named-pipe-server","last_synced_at":"2025-04-19T11:50:36.000Z","repository":{"id":162735407,"uuid":"268188305","full_name":"NewYaroslav/simple-named-pipe-server","owner":"NewYaroslav","description":"Очень простая серверная и клиентская библиотека Named Pipe, реализованная с использованием C++11","archived":false,"fork":false,"pushed_at":"2023-04-06T22:54:39.000Z","size":276,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T07:33:21.393Z","etag":null,"topics":["client","cpp","cpp11","easy","metatrader","mingw","mql4","mt4","named-pipe","server","simple-named-pipe-server","trading","win32"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NewYaroslav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-31T01:23:10.000Z","updated_at":"2025-02-17T03:44:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e96e5ea-9eaa-476d-85b1-932615966bdb","html_url":"https://github.com/NewYaroslav/simple-named-pipe-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewYaroslav%2Fsimple-named-pipe-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewYaroslav%2Fsimple-named-pipe-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewYaroslav%2Fsimple-named-pipe-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewYaroslav%2Fsimple-named-pipe-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NewYaroslav","download_url":"https://codeload.github.com/NewYaroslav/simple-named-pipe-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249687144,"owners_count":21310994,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","cpp","cpp11","easy","metatrader","mingw","mql4","mt4","named-pipe","server","simple-named-pipe-server","trading","win32"],"created_at":"2024-11-11T02:16:30.858Z","updated_at":"2025-04-19T11:50:35.994Z","avatar_url":"https://github.com/NewYaroslav.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-named-pipe-server\nОчень простая, многопоточная серверная и клиентская библиотека Named Pipe, реализованная с использованием C++11.\n\nПроект был проверен на компиляторе *mingw 7.3.0 x64*. Папка *code_blocks* содержит примеры для *IDE Code::Blocks*. Не забудьте в проектах указать свой компилятор, иначе проект не соберется.\n \n## Особенности использования Named Pipe сервера \n\n* Для отправки сообщения всем клиентам используйте метод 'send_all'.\n* Чтобы отправить сообщение конкретному клиенту, используйте метод 'send' клиента, указатель на которого передается в функции обратного вызова в момент наступления события 'on_open' или 'on_message'.\n* Чтобы узнать количество подключений, используйте  метод 'get_connections()'.\n\n## Важные фиксы\n\n* Методы 'get_connections()' и 'send_all' можно вызывать внутри 'on_open', 'on_message', 'on_close', 'on_error'\n\n## Пример сервера на C++\n\n```cpp\n#include \u003ciostream\u003e\n#include \"named-pipe-server.hpp\"\n\nint main() {\n    /* в конструкторе сервера можно также задать размер буфера */\n    SimpleNamedPipe::NamedPipeServer server(\"my_server\");\n\n    /* обработчики событий */\n    server.on_open = [\u0026](SimpleNamedPipe::NamedPipeServer::Connection* connection) {\n        std::cout \u003c\u003c \"open, handle: \" \u003c\u003c connection-\u003eget_handle() \u003c\u003c std::endl;\n    };\n\n    server.on_message = [\u0026](SimpleNamedPipe::NamedPipeServer::Connection* connection, \n\t\t\tconst std::string \u0026in_message) {\n        /* обрабатываем входящие сообщения */\n        std::cout \u003c\u003c \"message \" \u003c\u003c in_message \u003c\u003c \", handle: \" \u003c\u003c connection-\u003eget_handle() \u003c\u003c std::endl;\n        connection-\u003esend(\"ok\");\n    };\n\n    server.on_close = [\u0026](SimpleNamedPipe::NamedPipeServer::Connection* connection) {\n        std::cout \u003c\u003c \"close, handle: \" \u003c\u003c connection-\u003eget_handle() \u003c\u003c std::endl;\n    };\n\n    server.on_error = [\u0026](SimpleNamedPipe::NamedPipeServer::Connection* connection, const std::error_code \u0026ec) {\n        std::cout \u003c\u003c \"error, handle: \" \u003c\u003c connection-\u003eget_handle() \u003c\u003c \", what \" \u003c\u003c ec.value() \u003c\u003c std::endl;\n    };\n\n    /* запускаем сервер */\n    server.start();\n    std::system(\"pause\");\n\n    /* останавливаем сервер \n     * (деструктор класса сам выполнит остановку, вызывать не обязательно)\n     */\n    server.stop();\n    std::cout \u003c\u003c \"close program\" \u003c\u003c std::endl;\n    return EXIT_SUCCESS;\n}\n```\n\n## Пример клиента на C++\n\n```cpp\n#include \u003ciostream\u003e\n#include \"named-pipe-client.hpp\"\n\nusing namespace std;\n\nint main() {\n    /* в конструкторе клиента можно также задать размер буфера */\n    SimpleNamedPipe::NamedPipeClient client(\"my_server\");\n\n    /* обработчики событий */\n    client.on_open = [\u0026]() {\n\tstd::cout \u003c\u003c \"open, handle: \" \u003c\u003c client.get_handle() \u003c\u003c std::endl;\n\tclient.send(\"Hello!\");\n    };\n\n    client.on_message = [\u0026](const std::string \u0026in_message) {\n\tstd::cout \u003c\u003c \"message \" \u003c\u003c in_message \u003c\u003c \", handle: \" \u003c\u003c client.get_handle() \u003c\u003c std::endl;\n\tclient.send(\"ok\");\n\t//client.close(); // можно закрыть соединение\n    };\n\t\n    client.on_close = [\u0026]() {\n\tstd::cout \u003c\u003c \"close, handle: \" \u003c\u003c client.get_handle() \u003c\u003c std::endl;\n    };\n\t\n    client.on_error = [\u0026](const std::error_code \u0026ec) {\n\tstd::cout \u003c\u003c \"error, handle: \" \u003c\u003c client.get_handle() \u003c\u003c \", what \" \u003c\u003c ec.value() \u003c\u003c std::endl;\n    };\n\n    /* запускаем клиент */\n    client.start();\n\t\n    std::system(\"pause\");\n    std::cout \u003c\u003c \"close program\" \u003c\u003c std::endl;\n    return EXIT_SUCCESS;\n}\n```\n\n## Пример клиента для Meta Trader 5\n\n```\n//+------------------------------------------------------------------+\n//|                                            named_pipe_client.mq5 |\n//|                                     Copyright 2021, NewYaroslav. |\n//|          https://github.com/NewYaroslav/simple-named-pipe-server |\n//+------------------------------------------------------------------+\n#include \"..\\include\\named_pipe_client.mqh\"\n\ninput string pipe_name      = \"test-pipe\"; // Named Pipe for the stream of quotes\ninput int    timer_period   = 10; // Timer period for processing incoming messages\n\nNamedPipeClient     *pipe           = NULL;\n\n//+------------------------------------------------------------------+\n//| NamedPipeClient function                                   |\n//+------------------------------------------------------------------+\nvoid NamedPipeClient::on_open(NamedPipeClient *pointer) {\n    Print(\"open connection with \", pointer.get_pipe_name());\n}\n\nvoid NamedPipeClient::on_close(NamedPipeClient *pointer) {\n    Print(\"closed connection with \", pointer.get_pipe_name());\n}\n\nvoid NamedPipeClient::on_message(NamedPipeClient *pointer, const string \u0026message) {\n    Print(\"message: \" + message);\n}\n\nvoid NamedPipeClient::on_error(NamedPipeClient *pointer, const string \u0026error_message) {\n    Print(\"Error! What: \" + error_message);\n}\n\n//+------------------------------------------------------------------+\n//| Expert initialization function                                   |\n//+------------------------------------------------------------------+\nint OnInit() {\n    if (pipe == NULL) {\n        if ((pipe = new NamedPipeClient(pipe_name)) == NULL) return(false);\n    }\n\n    EventSetMillisecondTimer(timer_period);\n    return(INIT_SUCCEEDED);\n}\n//+------------------------------------------------------------------+\n//| Expert deinitialization function                                 |\n//+------------------------------------------------------------------+\nvoid OnDeinit(const int reason) {\n    EventKillTimer();\n    if (pipe != NULL) delete pipe;\n}\n//+------------------------------------------------------------------+\n//| Expert tick function                                             |\n//+------------------------------------------------------------------+\nvoid OnTick() {\n\n}\n//+------------------------------------------------------------------+\n//| Timer function                                                   |\n//+------------------------------------------------------------------+\nvoid OnTimer() {\n    static int ticks = 0;\n    if (pipe != NULL) pipe.on_timer();\n    \n    ticks += timer_period;\n    if (ticks \u003e= 1000) {\n        ticks = 0;\n\n        if (pipe != NULL) {\n            if (pipe.connected()) {\n                const string str_ping = \"ping\";\n                pipe.write(str_ping);\n            } // if (pipe.connected())\n        } // if (pipe != NULL)\n    } // if (ticks \u003e= 1000)\n}\n//+------------------------------------------------------------------+\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnewyaroslav%2Fsimple-named-pipe-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnewyaroslav%2Fsimple-named-pipe-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnewyaroslav%2Fsimple-named-pipe-server/lists"}