Updating example to close when they receive "world".

This commit is contained in:
David Baird
2013-05-14 11:11:39 -06:00
parent 50c2d0e18d
commit b7825802b9
2 changed files with 10 additions and 9 deletions
+6 -6
View File
@@ -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;
}