Answer the question
In order to leave comments, you need to log in
Client Server C++ Python?
I'm learning C++ and playing around with Python at the same time, so I decided to write a simple console chat.
The C++ application will act as the client, and the script will act as the Python server.
The problem is that sending a message from C++ to Python seems to cause no problems, only the Cyrillic alphabet is not sent (in Python it gives out some Chinese characters).
But sending a message from Python to C++ causes one problem.
I get a message in the C ++ console and at the end some incomprehensible gibberish, I understand that there may be some problem with the encoding, but the main thing is that the message displays everything (naturally, only numbers and Latin), and at the end, whatever one may say, some symbols.
Help me please.
Answer the question
In order to leave comments, you need to log in
Solution:
In python, encode the message with Windows1251 encoding
data = 'Какое-то сообщение'
data.encode('cp1251')
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
char message[256]; //Создание массива для сообщения
std::memset(message, 0, sizeof message); //очистка от мусора
recv(ConnectServer, message, sizeof(message), NULL); //принятие сообщения
std::cout << message << std::endl; //вывод сообщения на экран
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question