Add initial implementation of ConnectTool with Dear ImGui and Steam Networking
- Created project files for ConnectTool including filters and user settings. - Added README.md with setup instructions and prerequisites for building the project. - Implemented imgui_hello.cpp as a simple Dear ImGui application using GLFW and OpenGL. - Developed online_game_tool.cpp for hosting and joining game rooms using Steam Networking. - Created p2p_chat.cpp for a peer-to-peer chat application utilizing Steam Networking. - Implemented steam_friends.cpp to display the user's Steam friends list. - Added TCP client and server classes for handling network communication. - Integrated TCP server and client functionality into online_game_tool for real-time data exchange.
This commit is contained in:
40
tcp/tcp_client.h
Normal file
40
tcp/tcp_client.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <functional>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
// TCP Client class
|
||||
class TCPClient {
|
||||
public:
|
||||
TCPClient(const std::string& host, int port);
|
||||
~TCPClient();
|
||||
|
||||
bool connect();
|
||||
void disconnect();
|
||||
void send(const std::string& message);
|
||||
void send(const char* data, size_t size);
|
||||
void setReceiveCallback(std::function<void(const std::string&)> callback);
|
||||
void setReceiveCallback(std::function<void(const char*, size_t)> callback);
|
||||
|
||||
private:
|
||||
void start_read();
|
||||
void handle_read(const boost::system::error_code& error, std::size_t bytes_transferred);
|
||||
|
||||
std::string host_;
|
||||
int port_;
|
||||
bool connected_;
|
||||
boost::asio::io_context io_context_;
|
||||
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work_;
|
||||
std::shared_ptr<tcp::socket> socket_;
|
||||
std::thread clientThread_;
|
||||
std::mutex socketMutex_;
|
||||
std::function<void(const std::string&)> receiveCallback_;
|
||||
std::function<void(const char*, size_t)> receiveCallbackBytes_;
|
||||
std::vector<char> buffer_;
|
||||
};
|
||||
Reference in New Issue
Block a user