Skip to content

Commit

Permalink
Cleanup and example README
Browse files Browse the repository at this point in the history
  • Loading branch information
abedra committed Oct 27, 2021
1 parent 45ef8c2 commit 39958e0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.18)
project(example)

set(CMAKE_CXX_STANDARD 20)
Expand Down
17 changes: 17 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Simple WebSocket Example

## Server

```shell
cd server
npm install
node index.js
```

## Client

```shell
cmake -Bbuild -H.
cmake --build build
./build/example
```
10 changes: 10 additions & 0 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <simple_websocket.hpp>
#include <csignal>

constexpr int FRAME_SIZE = 1024;

bool continueRunning = true;

void handleSignal(int _) {
std::cout << "Received shutdown signal, terminating" << std::endl;
continueRunning = false;
}

struct TestFrameParser final : SimpleWebSocket::FrameParser<std::string> {
std::string handlePing(const SimpleWebSocket::PingFrame &pingFrame) override {
return "ERROR: received unexpected ping frame";
Expand Down Expand Up @@ -36,6 +42,10 @@ struct TestFrameParser final : SimpleWebSocket::FrameParser<std::string> {
};

int main() {
signal(SIGHUP, handleSignal);
signal(SIGINT, handleSignal);
signal(SIGTERM, handleSignal);

Poco::Net::HTTPClientSession session{"localhost", 8080};
Poco::Net::HTTPRequest request{Poco::Net::HTTPRequest::HTTP_GET, "/", Poco::Net::HTTPMessage::HTTP_1_1};
Poco::Net::HTTPResponse response;
Expand Down

0 comments on commit 39958e0

Please sign in to comment.