ClpeSocket.h
Go to the documentation of this file.
1 // Definition of the Socket class
2 
3 #ifndef ClpeSocket_class
4 #define ClpeSocket_class
5 
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <netinet/in.h>
9 #include <netinet/tcp.h>
10 #include <netdb.h>
11 #include <unistd.h>
12 #include <string>
13 #include <arpa/inet.h>
14 #include <iostream>
15 #include <stdlib.h>
16 #include <stdio.h>
17 
18 #define SOCKET_CLIENT
19 
20 const int MAXCONNECTIONS = 5;
21 
22 using namespace std;
23 
25 {
26 public:
27  ClpeSocket();
28  virtual ~ClpeSocket();
29 
30  // Server initialization
31  bool create(int mcu_id);
32  bool bind(const char *host ,const int port, int mcu_id);
33  bool listen(int mcu_id) const;
34  bool accept(ClpeSocket *new_socket, int mcu_id) const;
35 
36  // Client initialization
37  bool connect(const string host, const int port, int mcu_id);
38 
39  // Data Transimission
40  bool send(unsigned char *s, int mcu_id) const;
41  bool recv(unsigned char *s, int mcu_id) const;
42 
43  void close(int mcu_id);
44 
45  void set_non_blocking(const bool, int mcu_id);
46 
47  bool is_valid_master() const { return m_sock_master != -1; }
48  bool is_valid_slave() const { return m_sock_slave!= -1; }
49 
50 private:
53  sockaddr_in m_addr;
54 
55 };
56 
57 
58 #endif
ClpeSocket::is_valid_slave
bool is_valid_slave() const
Definition: ClpeSocket.h:48
ClpeSocket
Definition: ClpeSocket.h:24
ClpeSocket::m_sock_slave
int m_sock_slave
Definition: ClpeSocket.h:52
ClpeSocket::is_valid_master
bool is_valid_master() const
Definition: ClpeSocket.h:47
ClpeSocket::m_sock_master
int m_sock_master
Definition: ClpeSocket.h:51
MAXCONNECTIONS
const int MAXCONNECTIONS
Definition: ClpeSocket.h:20
ClpeSocket::m_addr
sockaddr_in m_addr
Definition: ClpeSocket.h:53


clpe_sdk
Author(s): Can-lab Corporation
autogenerated on Wed Oct 12 2022 02:17:28