Socket.h 804 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
	void setHostIp(bytes);
/jdi/'s avatar
/jdi/ committed
26
27
28
29
	int (*callback)(Packet)=[](Packet a) {
		return 0;
	};

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

};

#endif /* SOCKET_H_ */