How to detect client character encoding

asciicharacter encodingclient-serverutf-8

I programmed a telnet server using C as programming language but I have a problem to send characters with emphases (é, è, à …). The character encoding is different between the telnet clients (windows, linux, putty, …).

What can I do to detect the character encoding of the clients which are connected to my server ?

Best Answer

Guessing the encoding of a message based on its byte values is always imperfect, although it can be made to give relatively accurate results. There are libraries available to do this, e.g. IBM's ICU.

But the preferable option is always either to standardize client and server on one encoding and always use that, or to force the client to declare the encoding of messages explicitly. It requires only a little programming effort and solves the entire question once and for all.