TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_socket_connection.hpp
1 
9 #ifndef TurtleBrains_SocketConnectionInterface_hpp
10 #define TurtleBrains_SocketConnectionInterface_hpp
11 
12 #include <turtle_brains/core/tb_configuration.hpp>
13 #if defined(tb_with_networking)
14 
15 #include <turtle_brains/core/tb_noncopyable.hpp>
16 #include <turtle_brains/core/tb_types.hpp>
17 
18 namespace tbImplementation { class SocketConnectionImplementation; };
19 
20 namespace TurtleBrains
21 {
22  namespace Network
23  {
24 
25  class PacketHandlerInterface;
26 
27  enum class SocketConnectionType
28  {
29  ServerStreamTCP,
30  ClientStreamTCP,
31  ServerPacketTCP,
32  ClientPacketTCP,
33  ServerPacketUDP,
34  ClientPacketUDP,
35  };
36 
37  tbCore::byte InvalidClientID(void);
38 
39  tbCore::tbString GetServerIP(const tbCore::tbString& serverName);
40 
41  class SocketConnection : public tbCore::Noncopyable
42  {
43  public:
44  explicit SocketConnection(const SocketConnectionType& connectionType);
45  ~SocketConnection(void);
46 
57  void SetManagedConnection(bool isManaged);
58 
64  void UpdateConnection(float deltaTime);
65 
69  //void SetPacketSize() //TCP interpreting the 1st or 1st and 2nd bytes as size, and processing a full packet.
70 
80  bool Connect(const tbCore::tbString& ip, const tbCore::uint16& port, PacketHandlerInterface& packetHandler);
81 
82 
83  void Disconnect(void);
84 
94  void DisconnectClient(const tbCore::byte clientID);
95 
105  bool IsConnected(void) const;
106 
113  bool IsClientConnected(const tbCore::byte clientID) const;
114 
122  bool SendPacket(const tbCore::byte* const packetData, const size_t& packetSize);
123 
133  bool SendPacketTo(const tbCore::byte* const packetData, const size_t& packetSize, const tbCore::byte clientID);
134 
139  tbCore::uint64 GetTotalBytesReceived(void) const;
140 
145  tbCore::uint32 GetRecentBytesReceived(void) const;
146 
153  tbCore::uint64 GetTotalBytesSent(void) const;
154 
161  tbCore::uint32 GetRecentBytesSent(void) const;
162 
167  void SetDebugFlag(void);
168 
173  tbCore::uint16 UnstableApi_GetClientPort(const tbCore::byte clientID);
174 
175  private:
176  tbImplementation::SocketConnectionImplementation* mImplementation;
177  };
178 
179  }; /* namespace Network */
180 }; /* namespace TurtleBrains */
181 
182 namespace tbNetwork = TurtleBrains::Network;
183 
184 #endif /* tb_with_networking */
185 #endif /* TurtleBrains_SocketConnectionInterface_hpp */
uint16_t uint16
Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
Definition: tb_types.hpp:26
Definition: tb_noncopyable.hpp:22
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
uint64_t uint64
Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1).
Definition: tb_types.hpp:30
uint8 byte
Unsigned integer with 8 bits (1 byte). Supports 256 values from 0 to 255.
Definition: tb_types.hpp:24
uint32_t uint32
Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1)...
Definition: tb_types.hpp:28
std::string tbString
Definition: tb_string.hpp:335
Definition: tb_application_dialog.hpp:19