Updating example to close when they receive "world".
This commit is contained in:
@@ -12,11 +12,12 @@ int main()
|
|||||||
WebSocket::pointer ws = WebSocket::from_url("ws://localhost:8126/foo");
|
WebSocket::pointer ws = WebSocket::from_url("ws://localhost:8126/foo");
|
||||||
assert(ws);
|
assert(ws);
|
||||||
ws->send("goodbye");
|
ws->send("goodbye");
|
||||||
while (true) {
|
ws->send("hello");
|
||||||
|
while (ws->getReadyState() != WebSocket::CLOSED) {
|
||||||
ws->poll();
|
ws->poll();
|
||||||
ws->dispatch([](const std::string & message) {
|
ws->dispatch([ws](const std::string & message) {
|
||||||
printf(">>> %s\n", message.c_str());
|
printf(">>> %s\n", message.c_str());
|
||||||
ws->close();
|
if (message == "world") { ws->close(); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+6
-6
@@ -4,24 +4,24 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
using easywsclient::WebSocket;
|
||||||
|
static WebSocket::pointer ws = NULL;
|
||||||
|
|
||||||
void handle_message(const std::string & message)
|
void handle_message(const std::string & message)
|
||||||
{
|
{
|
||||||
printf(">>> %s\n", message.c_str());
|
printf(">>> %s\n", message.c_str());
|
||||||
|
if (message == "world") { ws->close(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
using easywsclient::WebSocket;
|
ws = WebSocket::from_url("ws://localhost:8126/foo");
|
||||||
WebSocket::pointer ws = WebSocket::from_url("ws://localhost:8126/foo");
|
|
||||||
assert(ws);
|
assert(ws);
|
||||||
ws->send("goodbye");
|
ws->send("goodbye");
|
||||||
ws->send("hello");
|
ws->send("hello");
|
||||||
ws->close();
|
while (ws->getReadyState() != WebSocket::CLOSED) {
|
||||||
while(ws->getReadyState() != WebSocket::CLOSED)
|
|
||||||
{
|
|
||||||
ws->poll();
|
ws->poll();
|
||||||
ws->dispatch(handle_message);
|
ws->dispatch(handle_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user