/
yaseeeeechka
/
CenterControl
Обзор
Документация
Войти
/
yaseeeeechka
/
CenterControl
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
CenterControl_TCP/client.cpp
63 строки
2 KB
Yaroslava
New structure of Repo. TCP impl
11 дек 2025, 21:12
11 дек 2025, 21:12
6fdf9d7
Код
Авторство
О чём код?
#define _WINSOCK_DEPRECATED_NO_WARNINGS #include <SFML/Graphics.hpp> #include <string> #include <iostream> #include <vector> #include <functional> #include <memory> #include <unordered_map> #include <algorithm> #include <cmath> #include "include/GameFieldConfig.h" #include "include/MsgProtocol.h" #include "include/client/RoomScreenList.h" #include "include/client/Session.h" #include "include/client/AuthScreen.h" #include "include/client/TopScoresScreen.h" #include "include/client/GameScreen.h" #include "include/client/RoomScreen.h" #include "include/client/WindowApp.h" // ==================== Client ========================================== class Client { public: Client(std::string ip, uint16_t port) : server_ip_(std::move(ip)), port_(port) { #ifdef _WIN32 WSADATA wsa{}; if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) throw std::runtime_error("WSAStartup failed"); #endif sock_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock_ == INVALID_SOCKET) throw std::runtime_error("socket() failed"); addr_.sin_family = AF_INET; addr_.sin_port = htons(port_); addr_.sin_addr.s_addr = inet_addr(server_ip_.c_str()); } void Run() { if (connect(sock_, (sockaddr *) &addr_, sizeof(addr_)) == SOCKET_ERROR) throw std::runtime_error("connect() failed"); std::cout << "Connected to server\n"; Session session(sock_); WindowApp app; app.SetSession(&session); app.Run(); } private: std::string server_ip_; uint16_t port_; SOCKET sock_; sockaddr_in addr_{}; }; // ==================== main ============================================ int main() { try { Client client("127.0.0.1", 5000); client.Run(); } catch (std::exception &e) { std::cerr << e.what() << std::endl; } }