communicator-tcp.hpp
1 #ifndef MAMMUT_COMMUNICATOR_TCP_HPP_
2 #define MAMMUT_COMMUNICATOR_TCP_HPP_
3 
4 #ifdef MAMMUT_REMOTE
5 
6 #include "./communicator.hpp"
7 
8 #include "cstddef"
9 
10 namespace mammut{
11 
12 class ServerTcp;
13 
14 class CommunicatorTcp: public Communicator{
15 private:
16  int _socket;
17  mutable utils::LockPthreadMutex _lock;
18 public:
24  CommunicatorTcp(std::string serverAddress, uint16_t serverPort);
25 
30  CommunicatorTcp(const ServerTcp& serverTcp);
31 
32  ~CommunicatorTcp();
33  void send(const char* message, size_t messageLength) const;
34  bool receive(char* message, size_t messageLength) const;
35  utils::Lock& getLock() const;
36 };
37 
38 // A TCP based server.
39 class ServerTcp{
40 private:
41  int _listenSocket;
42 public:
47  ServerTcp(uint16_t listeningPort);
48  ~ServerTcp();
49 
54  int accept() const;
55 };
56 
57 }
58 
59 #endif
60 
61 #endif /* MAMMUT_COMMUNICATOR_TCP_HPP_ */