UDP client that performs the handshake, sends inputs and decodes server messages.
More...
#include <NetworkClient.hpp>
|
|
| NetworkClient () |
| | Creates a client with a closed socket.
|
| |
|
| ~NetworkClient () |
| | Stops the client and joins the network thread.
|
| |
|
| NetworkClient (const NetworkClient &)=delete |
| |
|
NetworkClient & | operator= (const NetworkClient &)=delete |
| |
| bool | connect (const std::string &host, const std::string &port) |
| | Resolves the server address, opens the socket and starts the network thread.
|
| |
|
void | sendHello () |
| | Sends a Hello handshake if not connected yet.
|
| |
| void | sendInput (std::uint32_t clientTick, rtype::protocol::InputAction actions) |
| | Sends an Input message with the next input sequence number.
|
| |
| void | sendQueryEntity (std::uint32_t networkId) |
| | Asks the server to describe an unknown entity.
|
| |
| void | send (const std::vector< std::uint8_t > &data) |
| | Sends raw bytes to the server.
|
| |
| bool | pollEvent (NetworkEvent &event) |
| | Pops the oldest connection event or raw message.
|
| |
| bool | pollReplicationEvent (ReplicationEvent &event) |
| | Pops the oldest replication message.
|
| |
| bool | isConnected () const |
| | Tells whether the server accepted the handshake.
|
| |
| bool | isRunning () const |
| | Tells whether the network thread is running.
|
| |
| std::uint32_t | getConnectionId () const |
| | Returns the id given by the server.
|
| |
|
void | stop () |
| | Closes the socket and joins the network thread.
|
| |
UDP client that performs the handshake, sends inputs and decodes server messages.
I/O runs on a dedicated thread, and received data is handed to the game loop through thread safe queues read with pollEvent() and pollReplicationEvent().
◆ connect()
| bool rtype::client::NetworkClient::connect |
( |
const std::string & | host, |
|
|
const std::string & | port ) |
Resolves the server address, opens the socket and starts the network thread.
- Parameters
-
| host | Server host name or IPv4 address. |
| port | Server UDP port. |
- Returns
- True on success, false if already running or resolution failed.
◆ sendInput()
Sends an Input message with the next input sequence number.
- Parameters
-
| clientTick | Current client frame counter. |
| actions | Actions currently held. |
◆ sendQueryEntity()
| void rtype::client::NetworkClient::sendQueryEntity |
( |
std::uint32_t | networkId | ) |
|
Asks the server to describe an unknown entity.
- Parameters
-
| networkId | Network id of the entity. |
◆ send()
| void rtype::client::NetworkClient::send |
( |
const std::vector< std::uint8_t > & | data | ) |
|
Sends raw bytes to the server.
- Parameters
-
| data | Datagram, ignored if empty or larger than MAX_PAYLOAD_SIZE. |
◆ pollEvent()
| bool rtype::client::NetworkClient::pollEvent |
( |
NetworkEvent & | event | ) |
|
Pops the oldest connection event or raw message.
- Parameters
-
- Returns
- True if an event was popped.
◆ pollReplicationEvent()
| bool rtype::client::NetworkClient::pollReplicationEvent |
( |
ReplicationEvent & | event | ) |
|
Pops the oldest replication message.
- Parameters
-
- Returns
- True if an event was popped.
◆ isConnected()
| bool rtype::client::NetworkClient::isConnected |
( |
| ) |
const |
Tells whether the server accepted the handshake.
- Returns
- True once Welcome was received.
◆ isRunning()
| bool rtype::client::NetworkClient::isRunning |
( |
| ) |
const |
Tells whether the network thread is running.
- Returns
- True between connect() and stop().
◆ getConnectionId()
| std::uint32_t rtype::client::NetworkClient::getConnectionId |
( |
| ) |
const |
Returns the id given by the server.
- Returns
- The connection id, or 0 if not connected.