summaryrefslogtreecommitdiff
path: root/src/aa_socket.h
blob: 8b077f3f2f3dae2c02bd0fc0f9f1fe3d18d81bce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef __SOCKET_H__
#define __SOCKET_H__

#include <string>

#include <netinet/in.h>
//#include <sys/socket.h>


/**
 * Exceptions
 */
struct Network_error {
	Network_error(const char *event, const char *err) {
		error = std::string(err) + " - in " + std::string(event);
	}
	std::string error;
};

class AASocket {
public:
  AASocket();
  ~AASocket();

  void listen(unsigned short port);
  void connect(const char *ip, unsigned short port);
  
  void send(const char* buf, unsigned int buf_size);
  int receive(char* buf, unsigned int buf_size);

  void send_string(std::string buf);
  std::string receive_string();

	void force_close();

private:
  struct sockaddr_in socketaddr;
  int socket;
	int bind_socket; // Tmp socket for listen.
};

#endif/*__SOCKET_H__*/