Socket.h 743 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
#define MAX_LENGTH 1024

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

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

};

#endif /* SOCKET_H_ */