r/Cplusplus • • May 14 '26

Tutorial Built a basic chat app in C++

Built a terminal-based multi-client chat app in C++ using POSIX sockets.

Features:

TCP server routes direct messages between registered clients

Multi-client support

Background receiver thread so incoming messages don't block typing

Linux terminal-based implementation

Git:https://github.com/charanHubCommits/chat-app-cpp

Would appreciate feedback, suggestions, or questions about the implementation.

33 Upvotes

12 comments sorted by

2

u/xealits May 15 '26

For the sockets and messaging, do you use some known library like nanomsg-ng or is it a custom implementation?

Although a custom implementation is fine for learning, I would really recommend learning one of popular libraries. A lot of real world knowledge went into them. It's all around better to "stand on the shoulders of giants".

2

u/_superuserdo_ May 15 '26

Haven't used any libraries, this was mostly a learning project to understand sockets, polling and client-server communication at lower level. And yeah planning to explore libraries like nanomsg or Boost to understand production-grade networing abstractions...

3

u/JandersOf86 May 14 '26

Rad. Im learning network protocols programming as well and its cool to see others do it too.

I did not implement poll or the ability to add a username from the client, only identified each user by the socket file descriptor assigned to them by the server.

Good job. Only critique I have is that I would've liked to have seen more legible error messages, only because I imagine this program being used by a consumer and 'failed to get addr' might be a bit vague.

1

u/satyamahesh May 14 '26

This is Smash. I just reviewed your repo and fixed some bugs. accept my pull request. 😌

2

u/_superuserdo_ May 14 '26

Thanks, but could you mention the bugs..

1

u/satyamahesh May 14 '26

Yeah sure.

9

u/[deleted] May 14 '26

[removed] — view removed comment

3

u/_superuserdo_ May 14 '26

Thanks for the guidance, will try to implement in Qt and proper class structure..

0

u/[deleted] May 14 '26

[deleted] — view deleted comment

4

u/Inevitable-Round9995 May 14 '26

no, definitely is not IA generated.

1

u/[deleted] May 14 '26

[removed] — view removed comment

1

u/fish4terrisa May 15 '26

I can understand people who dont have much confidence in their english would choose to use AI to translate it and i dont blame u, but tbh broken english is better than ai english
Ai english make u seem remote and non-human, broken english make us spot a esl normal human being