Answer the question
In order to leave comments, you need to log in
How to change the encoding, what's wrong?
Hello, I made a small program for chatting.
Here is the program server code:
#pragma comment(lib, "Ws2_32.lib")
#include<WinSock2.h>
#include<iostream>
#include<Ws2tcpip.h>
#include<ctime>
SOCKET Connect;
SOCKET* Connections;
SOCKET Listen;
int ClientCount = 0;
void SendMessageToClient(int ID) {
char* buffer = new char[1024];
for (;; Sleep(75)) {
memset(buffer, 0, sizeof(buffer));
if (recv( Connections[ID], buffer, 1024, NULL)) {
printf(buffer);
printf("\n");
for (int i = 0; i <= ClientCount; i++) {
send(Connections[i], buffer, strlen(buffer), NULL);
}
}
}
delete buffer;
}
int main() {
setlocale(LC_ALL, "russian");
WSAData data;
WORD version = MAKEWORD(2, 2);
int res = WSAStartup(version, &data);
if (res != 0) {
return 0;
}
struct addrinfo hints;
struct addrinfo * result;
Connections = (SOCKET*)calloc(64, sizeof(SOCKET));
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
getaddrinfo(NULL, "7770", &hints, &result);
Listen = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
bind(Listen, result->ai_addr, result->ai_addrlen);
listen(Listen, SOMAXCONN);
freeaddrinfo(result);
printf("Start server....");
char m_connect[] = "Connect...;;;5";
for (;; Sleep(75)) {
if (Connect = accept(Listen, NULL, NULL)) {
printf("Client connect...\n");
Connections[ClientCount] = Connect;
send(Connections[ClientCount], m_connect, strlen(m_connect), NULL);
ClientCount++;
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)SendMessageToClient, (LPVOID)(ClientCount - 1), NULL, NULL);
}
}
return 1;
}
Answer the question
In order to leave comments, you need to log in
#include <iostream>
#include <windows.h>
#include <io.h>
#include <fcntl.h>
int main() // wmain, получается, не обязателен
{
std::wstring s = L"Тут курят! Błąd, kurwa!";
// Проверка на юникодность. Если вышла бурда — такой компилятор фтопку!
MessageBoxW(0, s.c_str(), L"Test", MB_OK);
// Вот что надо сделать — так что не забывайте, что придётся работать не в UTF-8, а в wchar’ах
_setmode(_fileno(stdout), _O_U16TEXT);
std::wcout << s << std::endl;
// Задержка
std::cin.ignore(1);
return 0;
}
CONFIG += console c++11
, I had to remove the word console. It is advisable (but not required) to change from an entry point Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question