A simple header only library that implements a websocket client in c++
See examples in the ./examples
directory.
#include <iostream>
#include "websocket.hpp"
void listen(char* data, int length)
{
printf("testing:%s\n",data);
std::cout << length << std::endl;
}
int main()
{
websocket test;
void (*listener)(char*, int) = listen;
test.connectSocket("127.0.0.1", 8081, listen);
test.sendMessage("testing:whatthebif");
std::cout << "Sent message" << std::endl;
test.exit();
}
When compiling with websocket.hpp
, make sure to link pthread
and OpenSSL
as this library uses these libraries to allow for sending and receiving of data at the same time, and for secure websockets. Using g++
for example:
g++ yourFile.cpp -lpthread -lssl -o yourOutput