8#ifndef RTYPE_NETWORK_NETWORK_HPP_
9 #define RTYPE_NETWORK_NETWORK_HPP_
46 ClientNetwork(
const std::string &serverIp, uint16_t serverPort);
58 void start(
void)
override;
64 void stop(
void)
override;
77 std::optional<net::NetworkEvent>
pollEvent(
void)
override;
Network packet implementation for R-Type protocol.
std::vector< net::Packet > hasPendingPackets(void)
Check if there are pending packets in the event queue.
void readUdp(void)
Read UDP packets asynchronously.
asio::ip::tcp::socket _tcpSocket
TCP socket for communication.
void sendPacket(const net::Packet &packet, net::NetworkMode mode)
Send a packet to the server.
net::Header _udpHeader
UDP packet header.
std::string _serverIp
Server IP address.
bool _udpBound
Flag indicating if UDP is bound.
std::array< char, 65536 > _udpBuffer
Buffer for UDP packets.
void sendUdpHandshake(void)
Send UDP handshake to the server.
~ClientNetwork() override
Destructor for Client Network.
std::mutex _eventQueueMutex
Mutex for event queue synchronization.
net::Packet popPacket(void)
Pop a packet from the event queue.
bool isUdpReady(void) const
Check if UDP socket is ready.
std::deque< net::NetworkEvent > _eventQueue
Queue of network events.
uint32_t _sessionId
Client session ID.
void stop(void) override
Stop the network client.
net::Header _tcpHeader
TCP packet header.
std::thread _ioThread
Thread for running the I/O context.
uint16_t _serverPort
Server port number.
std::vector< uint8_t > _tcpBody
TCP packet body.
asio::ip::udp::endpoint _serverEndpoint
Server UDP endpoint.
void readTcpBody(void)
Read TCP packet body asynchronously.
void start(void) override
Start the network client.
asio::io_context _ioContext
ASIO I/O context.
asio::ip::udp::socket _udpSocket
UDP socket for communication.
void readTcpHeader(void)
Read TCP packet header asynchronously.
void publishEvent(net::NetworkEvent event)
Publish a network event.
std::optional< net::NetworkEvent > pollEvent(void) override
Poll for a network event.
asio::ip::udp::endpoint _udpSenderEndpoint
Endpoint of the UDP sender.
Interface for network event handling.
Interface for network operations.
Network packet with header and serializable body.
NetworkMode
Enum representing network transmission modes.
Represents a network event containing session ID and packet data.