TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D game development.
tb_socket_connection.h
1 
9 #ifndef _TurtleBrains_SocketConnectionInterface_h_
10 #define _TurtleBrains_SocketConnectionInterface_h_
11 
12 #include "../../core/tb_configuration.h"
13 #if defined(tb_with_networking)
14 
15 #include "../../core/tb_noncopyable.h"
16 #include "../../core/tb_types.h"
17 
18 namespace tbImplementation { class SocketConnectionImplementation; };
19 
20 namespace TurtleBrains
21 {
22  namespace Network
23  {
24  namespace Unstable
25  {
27 
28  class PacketHandlerInterface;
29 
30  enum class SocketConnectionType
31  {
32  ServerStreamTCP,
33  ClientStreamTCP,
34  ServerPacketTCP,
35  ClientPacketTCP,
36  ServerPacketUDP,
37  ClientPacketUDP,
38  };
39 
40  tbCore::tbString GetServerIP(const tbCore::tbString& serverName);
41 
42  class SocketConnection : public tbCore::Noncopyable
43  {
44  public:
45  explicit SocketConnection(const SocketConnectionType& connectionType, PacketHandlerInterface& packetHandler);
46  ~SocketConnection(void);
47 
51  //void SetPacketSize() //TCP interpreting the 1st or 1st and 2nd bytes as size, and processing a full packet.
52 
53  bool Connect(const tbCore::tbString& ip, const tbCore::uint16& port);
54  void Disconnect(void);
55 
59  bool IsConnected(void) const;
60 
64  size_t Poll(void); //Packets get handled via PacketHandlerInterface and connection status to ServerHandlerInterface?
65 
73  bool SendPacket(const tbCore::byte* const packetData, const size_t& packetSize);
74 
84  bool SendPacketTo(const tbCore::byte* const packetData, const size_t& packetSize, const tbCore::byte clientID);
85 
86  private:
87  tbImplementation::SocketConnectionImplementation* mImplementation;
88  };
89 
91  }; /* namespace Unstable */
92  }; /* namespace Network */
93 }; /* namespace TurtleBrains */
94 
96 
97 #endif /* tb_with_networking */
98 #endif /* _TurtleBrains_SocketConnectionInterface_h_ */
uint16_t uint16
Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
Definition: tb_types.h:26
Definition: tb_noncopyable.h:22
Here is some information about the primary namespace.
Definition: tb_application_dialog.h:21
uint8 byte
Unsigned integer with 8 bits (1 byte). Supports 256 values from 0 to 255.
Definition: tb_types.h:24
std::string tbString
Definition: tb_string.h:335
Definition: tb_http_request.h:27
Definition: tb_application_dialog.h:19