From the course: Web Servers and APIs using C++

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating the C++ server code

Creating the C++ server code - C++ Tutorial

From the course: Web Servers and APIs using C++

Start my 1-month free trial

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 is different than anything we've done so far. We're just going to…

Contents