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 pushcpp::EventThread()
{
	while (true) {
		/* attempt to connect */
		DEBUG("polling thread started");

		while (
			this->m_websocket == NULL ||
			((WebSocket::pointer)this->m_websocket)->
			getReadyState() == WebSocket::CLOSED
		) {
			DEBUG("Attempting to connect!");

			if (this->m_websocket != NULL)
				delete((WebSocket::pointer) this->m_websocket);

			this->m_websocket = (void*) WebSocket::from_url(m_url);
		}

		WebSocket::pointer ws = (WebSocket::pointer) this->m_websocket;

		DEBUG("connected, (re)subscribing to channels");

		while (ws->getReadyState() != WebSocket::CLOSED) {
			ws->poll(100);
			ws->dispatch([this, ws](const string & msg) {
				WS_Dispatch(msg);
			});

			if (m_wantDisconnect)
				ws->close();
		}

		DEBUG("Lost connection, readyState: %d", ws->getReadyState());
		this->m_socketId = "";

		for (auto it = m_channelData.begin(); it != m_channelData.end(); it++)
			it->second.clear();

		if (m_connectionEventHandler)
			m_connectionEventHandler(ConnectionEvent::DISCONNECTED);

		if (m_wantDisconnect)
			break;
	}

	m_wantDisconnect = false;

	DEBUG("thread was stopped");
}
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;
}
Exemple #5
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;
}
Exemple #6
0
int main(int argc, char* argv[]) {

	if (argc < 2) {
		std::cout << "Usage: ecg ws://<host>:<port>/<path>\n";
		exit(0);
	}

	ws = WebSocket::from_url(argv[1]);
	send_message("CONNECT\naccept-version:1.1,1.0\n\n");
	while (ws->getReadyState() != WebSocket::CLOSED) {
		ws->poll();
		ws->dispatch(handle_connect);
	}

	delete ws;
	return 0;
}