int main() { #ifdef _WIN32 INT rc; WSADATA wsaData; rc = WSAStartup(MAKEWORD(2, 2), &wsaData); if (rc) { printf("WSAStartup Failed.\n"); return 1; } #endif 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); } #ifdef _WIN32 WSACleanup(); #endif return 0; }
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; }
void send_message(const std::string & message) { std::string s(message); s.push_back('\0'); s.push_back('\n'); std::cout << ">>>" << s << "\n"; ws->send(s); }
int main() { using easywsclient::WebSocket; WebSocket::pointer ws = WebSocket::from_url("ws://localhost:8126/foo"); assert(ws); ws->send("goodbye"); while (true) { ws->poll(); ws->dispatch([](const std::string & message) { printf(">>> %s\n", message.c_str()); ws->close(); }); } return 0; }
int main() { ws = WebSocket::from_url("ws://10.242.5.212:8080"); assert(ws); std::string data = "{ \"data\": { \"cardnumber\": \"042F1919721D80\", \"expiry\": \"\", \"pin\": \"1234\", \"roles\": [ { \"profile\": \"1\", \"type\": \"11\" } ], \"serviceprovider\": \"1001\", \"staffid\": \"5070\", \"type\": \"operator\", \"valid\": true }, \"event\": \"cardpresented\", \"name\": \"cardevent\", \"terminalid\": \"3\", \"type\": \"PUT\", \"userid\": null }"; printf(">>> %s\n", data.c_str()); ws->send(data.c_str()); while (ws->getReadyState() != WebSocket::CLOSED) { ws->poll(); ws->dispatch(handle_message); } delete ws; return 0; }