I am trying to implement a sample code with Websocket client/server:
- works on both windows and linux
- supports multiple clients
- no extra dependencies, pure C/C++ easy to use code
For example, implementing something like a chat room that accepts many users, would be a great base for me to understand how Websockets work and use them in my project.
I am looking at this website and I see this example of Websockets in C++.
I am using Clion IDE which uses MinGW compiler and these headers do not exist:
#include <netinet/in.h>
#include <netdb.h>
Auto-code-completion suggests these headers:
#include <winsock.h>
or
#include <winsock2.h>
Even though I see no errors on my IDE with those headers, when I run the code I get linking errors:
CMakeFiles\server_client.dir/objects.a(server.cpp.obj): In function `main':
C:/Users/Shiro/ClionProjects/server_client/server.cpp:44: undefined reference to `listen@8'
C:/Users/Shiro/ClionProjects/server_client/server.cpp:58: undefined reference to `select@20'
C:/Users/Shiro/ClionProjects/server_client/server.cpp:66: undefined reference to `__WSAFDIsSet@8'
collect2.exe: error: ld returned 1 exit status
On a sidenote, is this code even good to implement a Websocket client/server in C++ ? I want this to work on both windows and linux and have no external dependencies. Just pure C/C++. A couple of libraries I saw (like libwebsockets) were way too confusing and over-complicated to me, and they lack of any documentation or any examples. I did not understand a single line of code. Websockets in other languages like Java or C# are way more straightforward. Can someone point me in the right direction please ?