Socket.h 809 Bytes
Newer Older
/jdi/'s avatar
basics  
/jdi/ committed
1
2
3
4
5
6
7
8
9
10
11
/*
 * Socket.h
 *
 *  Created on: 02.09.2015
 *      Author: jdi
 */

#ifndef SOCKET_H_
#define SOCKET_H_

#include <asio.hpp>
/jdi/'s avatar
/jdi/ committed
12
#include "Packet.h"
/jdi/'s avatar
/jdi/ committed
13
#include "Types.h"
/jdi/'s avatar
/jdi/ committed
14
//#include "Types.h"
/jdi/'s avatar
basics  
/jdi/ committed
15

/jdi/'s avatar
/jdi/ committed
16
17
#define MAX_LENGTH 1024

/jdi/'s avatar
basics  
/jdi/ committed
18
19
class Socket {
public:
/jdi/'s avatar
/jdi/ committed
20
	Socket(asio::io_service&);
/jdi/'s avatar
/jdi/ committed
21
22
	virtual ~Socket() {
	}
/jdi/'s avatar
/jdi/ committed
23
	void init(short, short);
/jdi/'s avatar
basics  
/jdi/ committed
24
25
	void send(bytes);
	void listen();
/jdi/'s avatar
/jdi/ committed
26
	void setHostIp(ipAddr);
/jdi/'s avatar
/jdi/ committed
27
28
29
30
	int (*callback)(Packet)=[](Packet a) {
		return 0;
	};

/jdi/'s avatar
basics  
/jdi/ committed
31
private:
/jdi/'s avatar
/jdi/ committed
32
33
	asio::ip::udp::socket send_socket_;
	asio::ip::udp::socket receive_socket_;
/jdi/'s avatar
/jdi/ committed
34
	//asio::ip::udp::resolver resolver;
/jdi/'s avatar
basics  
/jdi/ committed
35
36
	asio::ip::udp::endpoint broadcast_endpoint_;
	asio::ip::udp::endpoint remote_endpoint_;
/jdi/'s avatar
/jdi/ committed
37
	asio::ip::udp::endpoint wildcard_endpoint_;
/jdi/'s avatar
basics  
/jdi/ committed
38
	asio::ip::udp::endpoint local_endpoint_;
/jdi/'s avatar
/jdi/ committed
39
	bytes data = bytes(MAX_LENGTH);
/jdi/'s avatar
/jdi/ committed
40
	ipAddr local_ip;
/jdi/'s avatar
basics  
/jdi/ committed
41
42
43
44

};

#endif /* SOCKET_H_ */