tcp_socket.h
Go to the documentation of this file.
1 #ifndef TCPSOCKET_H
2 #define TCPSOCKET_H
3 
4 namespace argos {
5  class CTCPSocket;
6 }
7 
8 #include <argos3/core/utility/datatypes/byte_array.h>
9 #include <argos3/core/utility/datatypes/datatypes.h>
10 
11 namespace argos {
12 
13  class CTCPSocket {
14 
15  public:
16 
17  CTCPSocket(int n_stream = -1);
18 
19  ~CTCPSocket();
20 
25  inline bool IsConnected() const {
26  return m_nStream != -1;
27  }
28 
33  inline int GetStream() const {
34  return m_nStream;
35  }
36 
41  inline const std::string& GetAddress() const {
42  return m_strAddress;
43  }
44 
53  void Connect(const std::string& str_hostname,
54  SInt32 n_port);
55 
65  void Listen(SInt32 n_port,
66  SInt32 n_queue_length = 10);
67 
78  void Accept(CTCPSocket& c_socket);
79 
84  void Disconnect();
85 
92  void SendBuffer(const UInt8* pun_buffer,
93  size_t un_size);
94 
102  bool ReceiveBuffer(UInt8* pun_buffer,
103  size_t un_size);
104 
118  void SendByteArray(const CByteArray& c_byte_array);
119 
134  bool ReceiveByteArray(CByteArray& c_byte_array);
135 
136  private:
137 
139  int m_nStream;
141  std::string m_strAddress;
142 
143  };
144 
145 }
146 
147 #endif
signed int SInt32
32-bit signed integer.
Definition: datatypes.h:93
bool ReceiveByteArray(CByteArray &c_byte_array)
Receives the passed byte array through the socket.
Definition: tcp_socket.cpp:199
void Listen(SInt32 n_port, SInt32 n_queue_length=10)
Listens for connections on the specified local port.
Definition: tcp_socket.cpp:72
void SendByteArray(const CByteArray &c_byte_array)
Sends the passed byte array through the socket.
Definition: tcp_socket.cpp:188
unsigned char UInt8
8-bit unsigned integer.
Definition: datatypes.h:60
void SendBuffer(const UInt8 *pun_buffer, size_t un_size)
Sends the passed buffer through the socket.
Definition: tcp_socket.cpp:152
bool ReceiveBuffer(UInt8 *pun_buffer, size_t un_size)
Fills the passed buffer with the data received through the socket.
Definition: tcp_socket.cpp:169
CTCPSocket(int n_stream=-1)
Definition: tcp_socket.cpp:18
void Disconnect()
Close the socket.
Definition: tcp_socket.cpp:143
void Connect(const std::string &str_hostname, SInt32 n_port)
Connects this socket to the specified hostname and port.
Definition: tcp_socket.cpp:32
const std::string & GetAddress() const
Returns a string containing the IPv4 address in dot notation.
Definition: tcp_socket.h:41
int GetStream() const
Returns the socket stream.
Definition: tcp_socket.h:33
Byte array utility class.
Definition: byte_array.h:28
bool IsConnected() const
Returns true if the socket is connected.
Definition: tcp_socket.h:25
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
void Accept(CTCPSocket &c_socket)
Accept a connection from a client.
Definition: tcp_socket.cpp:127