Copied code from Sending string over UDP in C++. C-style code in C++ question.
Let's make this solution to be a real C++ answer!
- order of includes
- char -> std string
- int error code -> exceptions
- cerr for errors
- use reinterpret cast
- print error message
- add root namespace (just to highlight network functions)
- another method to create destination address
- don't bind on client side
- close file descriptor
- separate function for sending data (pass data as string_view)