Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dual WebSocket channels on a C++ server #2767

Closed
nekkkoS opened this issue Nov 14, 2023 · 1 comment
Closed

Dual WebSocket channels on a C++ server #2767

nekkkoS opened this issue Nov 14, 2023 · 1 comment

Comments

@nekkkoS
Copy link

nekkkoS commented Nov 14, 2023

I've explored the example server available at this link #2766 https://github.com/vinniefalco/CppCon2018, and I'm a little unsure of the best approach to implementing a particular functionality. I need to set up two WebSocket channels on the same server, both serving different purposes.

The first WebSocket connection is supposed to consistently send data to the client at a high frequency (The server receives data about hardware performance and sends it to the client). Meanwhile, the second connection is intended to receive alerts and commands to control the server.

Could you please give recommendations or point me in the right direction on how to achieve this?

@ashtum
Copy link
Collaborator

ashtum commented Nov 14, 2023

In the handshaking process, you have the flexibility to use different request-target values. In the client-side code, you can pass a different target parameter to async_handshake, while in the server-side code, you can utilize the specified overload of async_accept to inspect the request-target field in the request and decide what to do with the connection.

Alternatively, you can initiate communication with the server by sending a message at the beginning of each connection. Inside the server, after reading the initial message, you can determine the appropriate actions to take based on the content. For instance, if you are using JSON messages, a message could look like this:

{
    "role": "monitoring"
}

@nekkkoS nekkkoS closed this as completed Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants