-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteStation.cpp
More file actions
54 lines (44 loc) · 1.56 KB
/
RemoteStation.cpp
File metadata and controls
54 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "RemoteStation.h"
namespace securityServer {
RemoteStation::RemoteStation(boost::asio::io_service& io_service) :
socket_(io_service) {
}
void RemoteStation::send(const securityClient::Packet & packet) {
boost::asio::streambuf buf;
std::ostream os(&buf);
boost::archive::text_oarchive ar(os);
ar & packet;
size_t header = buf.size();
std::vector < boost::asio::const_buffer > buffers;
buffers.push_back(boost::asio::buffer(&header, sizeof(header)));
buffers.push_back(buf.data());
boost::asio::write(socket, buffers);
}
void RemoteStation::startListening() {
size_t header;
boost::asio::async_read(socket_,
boost::asio::buffer(&header, sizeof(header)),
boost::bind(&RemoteStation::handle_read_data, shared_from_this(),
boost::asio::placeholders::error));
boost::asio::streambuf buf;
boost::asio::read(socket_, buf.prepare(header));
buf.commit(header);
std::istream is(&buf);
boost::archive::text_iarchive ar(is);
securityClient::Packet packet;
ar & packet;
std::cout << "Client id recev: " << packet.client_id_ << "\n";
}
void RemoteStation::handle_read_data(const size_t header,
const boost::system::error_code& error) {
boost::asio::streambuf buf;
boost::asio::async_read(socket_, buf.prepare(header),
boost::bind(&RemoteStation::handle_read_packet,shared_from_this(),buf,
boost::asio::placeholders::error));
}
void RemoteStation::handle_read_packet(const boost::asio::streambuf &buf, boost::system::error_code &error){
}
RemoteStation::~RemoteStation() {
// TODO Auto-generated destructor stub
}
} /* namespace securityServer */