source: BAORadio/libindi/v1/BAOTest/Socket.h @ 612

Last change on this file since 612 was 493, checked in by frichard, 14 years ago

Le programme gère mieux les connexion/déconnexion des microcontrôleurs.

File size: 895 bytes
Line 
1// Definition of the Socket class
2
3#ifndef Socket_class
4#define Socket_class
5
6
7#include <sys/types.h>
8#include <sys/socket.h>
9#include <netinet/in.h>
10#include <netdb.h>
11#include <unistd.h>
12#include <string>
13#include <arpa/inet.h>
14#include <iostream>
15
16
17const int MAXHOSTNAME = 200;
18const int MAXCONNECTIONS = 5;
19const int MAXRECV = 5000;
20
21
22
23class Socket
24{
25 public:
26  Socket();
27  virtual ~Socket();
28
29
30  // Server initialization
31  bool create();
32  bool bind ( const int port );
33  bool listen() const;
34  bool accept ( Socket& ) const;
35
36  // Client initialization
37  bool connect ( const std::string host, const int port );
38
39  // Data Transimission
40  bool send ( const std::string ) const;
41  int recv ( std::string& ) const;
42
43
44  void set_non_blocking ( const bool );
45
46  bool is_valid() const { return m_sock != -1; }
47
48  bool shutdown();
49
50 private:
51
52  int m_sock;
53  sockaddr_in m_addr;
54
55
56
57
58};
59
60
61#endif
Note: See TracBrowser for help on using the repository browser.