Question

I'm working on Ubuntu and I'm writing a server in c++ that uses the websocket++ library, which works perfectly for incoming websocket connections from browsers (I used javascript there).

Now I want to do some performance tests and connect a lot of automated 'fake' clients.

For that I wanted to write a program that gets started multiple times and that connects to that server. To do this, I tried the following code:

#include "websocketpp/src/roles/client.hpp"
#include "websocketpp/src/websocketpp.hpp"

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>

#include "FakeClient.h"

using boost::asio::ip::tcp;
using websocketpp::client;


FakeClient::FakeClient()
{
    thisPointer = boost::shared_ptr<FakeClient>(this);

    client endpoint(thisPointer);

    endpoint.alog().unset_level(websocketpp::log::alevel::ALL);
    endpoint.elog().unset_level(websocketpp::log::elevel::ALL);

    endpoint.elog().set_level(websocketpp::log::elevel::RERROR);
    endpoint.elog().set_level(websocketpp::log::elevel::FATAL);

    endpoint.connect("ws://localhost:9001/");

    boost::thread t(&FakeClient::run, *this);

    t.join();
}

void FakeClient::run()
{
    while(true)
    {
        // send stuff here
        usleep(100);
    }
}

Now when the server is started and the fake clients try to connect, I only get the following error:

2013-04-23T16:00:02 [2] fail_on_expire timer expired with message: Timeout on WebSocket handshake

When the server is not started though, no error message appears, so there is definitely some kind of connection happening. But I can't figure out what I'm doing wrong. Is it even possible to easily connect 2 binary programs via the websocket++ lib?

For the best performance testing results, the websockets should be used for communication between the server and the fake clients, i guess.

Thank you for your help,

Koonschi

Was it helpful?

Solution

WebSocket++ author here. WebSocket++ is definitely able to talk to itself. I've created some examples to demonstrate how to do this. Take a look at the following two (Note: these examples use the most recent 0.3.x version of the library).

Telemetry Client: This client connects to the specified WebSocket server and sends a message once a second. https://github.com/zaphoyd/websocketpp/blob/experimental/examples/telemetry_client/telemetry_client.cpp

Print Server: This server listens for connections and prints out any messages received. https://github.com/zaphoyd/websocketpp/blob/experimental/examples/print_server/print_server.cpp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top