1
votes

I'm trying to send data from the server written in Erlang:

gen_tcp:send(Socket, "Server connection refused \r\n").

It's ok. But when I try to send data with non-latin symbols, e. g. cyrillic, I see the error report. For example if i use:

gen_tcp:send(Socket, "Привет \r\n").

Instead of string I see error report. How do I send a string with non-latin characters via TCP socket from Erlang?

1
Correct me if I'm wrong, but weren't sockets just for sending byte streams? For ASCII there usually are convenience methods that may treat a string as just bytes, but for normal text you need to use a character encoding. - Joey

1 Answers

2
votes

Try this:

8> unicode:characters_to_binary("пириуэт да").
<<208,191,208,184,209,128,208,184,209,131,209,141,209,130,
  32,208,180,208,176>>
9>