Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
32fa79e8
Commit
32fa79e8
authored
May 30, 2022
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update hello-client example
parent
c2e3d0e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
3 deletions
+14
-3
examples/web_socket/hello-client.cpp
examples/web_socket/hello-client.cpp
+14
-3
No files found.
examples/web_socket/hello-client.cpp
View file @
32fa79e8
...
...
@@ -21,7 +21,8 @@ struct config : caf::actor_system_config {
.
add
<
std
::
string
>
(
"host"
,
"TCP endpoint to connect to"
)
.
add
<
uint16_t
>
(
"port,p"
,
"port for connecting to the host"
)
.
add
<
std
::
string
>
(
"endpoint"
,
"sets the Request-URI field"
)
.
add
<
std
::
string
>
(
"protocols"
,
"sets the Sec-WebSocket-Protocol field"
);
.
add
<
std
::
string
>
(
"protocols"
,
"sets the Sec-WebSocket-Protocol field"
)
.
add
<
size_t
>
(
"max,m"
,
"maximum number of message to receive"
);
}
};
...
...
@@ -65,6 +66,13 @@ int caf_main(caf::actor_system& sys, const config& cfg) {
std
::
cerr
<<
"*** error while reading from the WebSocket: "
<<
to_string
(
what
)
<<
'\n'
;
})
.
compose
([
self
](
auto
in
)
{
if
(
auto
limit
=
caf
::
get_as
<
size_t
>
(
self
->
config
(),
"max"
))
{
return
std
::
move
(
in
).
take
(
*
limit
).
as_observable
();
}
else
{
return
std
::
move
(
in
).
as_observable
();
}
})
.
for_each
([](
const
ws
::
frame
&
msg
)
{
if
(
msg
.
is_text
())
{
std
::
cout
<<
"Server: "
<<
msg
.
as_text
()
<<
'\n'
;
...
...
@@ -73,8 +81,11 @@ int caf_main(caf::actor_system& sys, const config& cfg) {
<<
msg
.
as_binary
().
size
()
<<
"]
\n
"
;
}
});
// Send our hello message.
self
->
make_observable
().
just
(
ws
::
frame
{
hello
}).
subscribe
(
push
);
// Send our hello message and wait until the server closes the socket.
self
->
make_observable
()
.
just
(
ws
::
frame
{
hello
})
.
concat
(
self
->
make_observable
().
never
<
ws
::
frame
>
())
.
subscribe
(
push
);
});
});
return
EXIT_SUCCESS
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment