From the course: Web Servers and APIs using C++
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Creating the C++ server code - C++ Tutorial
From the course: Web Servers and APIs using C++
Creating the C++ server code
- [Instructor] In order to implement web socket, we need to add two header files, unordered set and mutex. So let's go to the main cpp, go to the top of the file and we're gonna say include unordered underscore set and include mutex. Unordered set is a container, which stores data in no particular order. The mutex helps make the code thread safe. Now we go down to the main function. And then right here in the main function, we're gonna do std colon colon mutex mtx. And below it, we're gonna say std colon colon unordered underscore set. And this is gonna be an unordered set of crow colon colon web socket colon colon connection and an asterisk pointer. And then this is gonna be called users. Okay then we go down just a little bit and we'll make this our first route. Give us a little space. Crow underscore route app comma ws. As we said in the JavaScript file, ws is our route handler for web socket. Now what comes next…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.