Socket.h 835 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
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(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);
/jdi/'s avatar
/jdi/ committed
29
30
31
32
	int (*callback)(Packet)=[](Packet a) {
		return 0;
	};

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

};

#endif /* SOCKET_H_ */