r/codereview • u/kouroshtkk01 • Apr 08 '26
TCP/UDP Chat Server and Client
https://github.com/kouroshtkk/TCP-UDP-Chat-Server-Client
I'm a second year bachelor CS student and wrote this project for the operating systems and network course, I did not use AI for coding at all, only i wrote README with AI.
I will genuinely appreciate any reviews and tips, tell me if I'm cooked.
2
Upvotes
1
u/kingguru Apr 08 '26
Don't know if this is part of the exercise but you should really, really consider avoiding using threads the way you do here.
Threads makes code orders of magnitude more complex and from the looks of it, you don't need threads at all.
As an example of how complex the use threads can be, consider your use of
pthread_cancel. That is an extremely difficult function to use correctly and am not able to determine if you have done so:Don't worry if you cannot answer any of these questions. Neither can I and that's my entire point. Dealing with thread is difficult and introducing thread cancellation makes it close to impossible to convince yourself your code is correct.
Instead consider avoiding the use of threads and blocking I/O and have a loot at
poll()and similar functions instead.It will make your code much, much easier to reason about and most likely more efficient.
Hope you find this useful. Best of luck