|
| 1 | +# Room-Based Asynchronous Chat Server |
| 2 | + |
| 3 | +Simple example of a high performance room-based chat server. Built with oat++ (AKA oatpp) web framework using Async API. |
| 4 | +Server can handle a large number of simultaneous connections. |
| 5 | + |
| 6 | +See more: |
| 7 | + |
| 8 | +- [Oat++ Website](https://oatpp.io/) |
| 9 | +- [Oat++ Github Repository](https://github.com/oatpp/oatpp) |
| 10 | +- [Get Started With Oat++](https://oatpp.io/docs/start) |
| 11 | + |
| 12 | +## Overview |
| 13 | + |
| 14 | +User connectes on a websocket endpoint `ws://localhost:8000/ws/chat/{room_name}/?nickname={nickname}` and |
| 15 | +enters the chat room `room_name`. User will appear in the chat as a `nickname`. |
| 16 | + |
| 17 | +If user is the first user in the room,- new room will be automatically created. |
| 18 | + |
| 19 | +Each message that user send to the chat room will be delivered to every participant of the room. |
| 20 | + |
| 21 | +### Project layout |
| 22 | + |
| 23 | +``` |
| 24 | +|- CMakeLists.txt // projects CMakeLists.txt |
| 25 | +|- src/ |
| 26 | +| | |
| 27 | +| |- controller/ |
| 28 | +| | | |
| 29 | +| | |- RoomsController.hpp // ApiController with websocket endpoint |
| 30 | +| | |
| 31 | +| |- rooms/ |
| 32 | +| | | |
| 33 | +| | |- Lobby.hpp // Class for managing new peers and assigning them to rooms |
| 34 | +| | |- Peer.hpp // Class representing one peer of a chat |
| 35 | +| | |- Room.hpp // Class representing one chat room |
| 36 | +| | |
| 37 | +| |- AppComponent.hpp // Application config. |
| 38 | +| |- App.cpp // main() is here |
| 39 | +| |
| 40 | +|- utility/install-oatpp-modules.sh // utility script to install required oatpp-modules. |
| 41 | +``` |
| 42 | + |
| 43 | +## Build and Run |
| 44 | + |
| 45 | +### Using CMake |
| 46 | + |
| 47 | +**Requires:** [oatpp](https://github.com/oatpp/oatpp), and [oatpp-websocket](https://github.com/oatpp/oatpp-websocket) |
| 48 | +modules installed. You may run `utility/install-oatpp-modules.sh` |
| 49 | +script to install required oatpp modules. |
| 50 | + |
| 51 | +After all dependencies satisfied: |
| 52 | + |
| 53 | +``` |
| 54 | +$ mkdir build && cd build |
| 55 | +$ cmake .. |
| 56 | +$ make |
| 57 | +$ ./async-server-rooms-exe # - run application. |
| 58 | +``` |
| 59 | + |
| 60 | +## How to test |
| 61 | + |
| 62 | +Browser tab1: |
| 63 | + |
| 64 | +- Goto [http://www.websocket.org/echo.html](http://www.websocket.org/echo.html). |
| 65 | +- In the "location" field put - `ws://localhost:8000/ws/chat/Room1/?nickname=Nick` |
| 66 | +- Press "Connect" button. |
| 67 | +- Verify recieved `RECEIVED: Nick joined Room1` |
| 68 | + |
| 69 | +Browser tab2: |
| 70 | + |
| 71 | +- Goto [http://www.websocket.org/echo.html](http://www.websocket.org/echo.html). |
| 72 | +- In the "location" field put - `ws://localhost:8000/ws/chat/Room1/?nickname=Alex` |
| 73 | +- Press "Connect" button. |
| 74 | +- Verify recieved `RECEIVED: Alex joined Room1` |
| 75 | + |
| 76 | +Now try to send messages from both browser tabs and see that messages are delivered to both participants. |
| 77 | + |
0 commit comments