2015-09-23 20:29:29 +00:00
|
|
|
/*
|
|
|
|
* Socket.h
|
|
|
|
*
|
|
|
|
* Created on: 02.09.2015
|
|
|
|
* Author: jdi
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SOCKET_H_
|
|
|
|
#define SOCKET_H_
|
|
|
|
|
|
|
|
#include <asio.hpp>
|
2015-09-25 23:24:03 +00:00
|
|
|
#include "Packet.h"
|
2015-09-27 10:23:12 +00:00
|
|
|
#include "Types.h"
|
2015-09-23 20:29:29 +00:00
|
|
|
|
2015-09-24 18:01:26 +00:00
|
|
|
#define MAX_LENGTH 1024
|
|
|
|
|
2015-09-23 20:29:29 +00:00
|
|
|
class Socket {
|
|
|
|
public:
|
2015-09-24 18:01:26 +00:00
|
|
|
Socket(asio::io_service&);
|
2015-09-25 23:24:03 +00:00
|
|
|
virtual ~Socket() {
|
|
|
|
}
|
2015-09-24 18:01:26 +00:00
|
|
|
void init(short, short);
|
2015-09-23 20:29:29 +00:00
|
|
|
void send(bytes);
|
|
|
|
void listen();
|
2015-09-25 23:24:03 +00:00
|
|
|
int (*callback)(Packet)=[](Packet a) {
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2015-09-23 20:29:29 +00:00
|
|
|
private:
|
2015-09-24 18:01:26 +00:00
|
|
|
asio::ip::udp::socket send_socket_;
|
|
|
|
asio::ip::udp::socket receive_socket_;
|
2015-09-27 10:23:12 +00:00
|
|
|
asio::ip::udp::resolver resolver;
|
2015-09-23 20:29:29 +00:00
|
|
|
asio::ip::udp::endpoint broadcast_endpoint_;
|
|
|
|
asio::ip::udp::endpoint remote_endpoint_;
|
2015-09-24 18:01:26 +00:00
|
|
|
asio::ip::udp::endpoint wildcard_endpoint_;
|
2015-09-23 20:29:29 +00:00
|
|
|
asio::ip::udp::endpoint local_endpoint_;
|
2015-09-26 01:48:10 +00:00
|
|
|
bytes data = bytes(MAX_LENGTH);
|
2015-09-23 20:29:29 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SOCKET_H_ */
|