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