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

#ifndef SOCKET_H_
#define SOCKET_H_

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

/jdi/'s avatar
/jdi/ committed
15
16
17
#define SRC_PORT 29809
#define DST_PORT 29808

/jdi/'s avatar
/jdi/ committed
18
19
#define MAX_LENGTH 1024

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

/jdi/'s avatar
basics  
/jdi/ committed
33
private:
/jdi/'s avatar
/jdi/ committed
34
35
36
37
38
39
40
	boost::asio::ip::udp::socket send_socket_;
	boost::asio::ip::udp::socket receive_socket_;
	boost::asio::ip::udp::endpoint broadcast_endpoint_;
	boost::asio::ip::udp::endpoint remote_endpoint_;
	boost::asio::ip::udp::endpoint wildcard_endpoint_;
	boost::asio::ip::udp::endpoint local_endpoint_;
	boost::asio::deadline_timer timer;
/jdi/'s avatar
/jdi/ committed
41
	bytes data = bytes(MAX_LENGTH);
/jdi/'s avatar
/jdi/ committed
42
	ipAddr local_ip;
43
	int initialized = 0;
/jdi/'s avatar
basics  
/jdi/ committed
44
45
46
47

};

#endif /* SOCKET_H_ */