28 lines
647 B
C++
28 lines
647 B
C++
#include "easywsclient.hpp"
|
|
//#include "easywsclient.cpp" // <-- include only if you don't want compile separately
|
|
#include <assert.h>
|
|
#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()
|
|
{
|
|
ws = WebSocket::from_url("ws://localhost:8126/foo");
|
|
assert(ws);
|
|
ws->send("goodbye");
|
|
ws->send("hello");
|
|
while (ws->getReadyState() != WebSocket::CLOSED) {
|
|
ws->poll();
|
|
ws->dispatch(handle_message);
|
|
}
|
|
return 0;
|
|
}
|