-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathTcpHandler.h
More file actions
39 lines (31 loc) · 890 Bytes
/
TcpHandler.h
File metadata and controls
39 lines (31 loc) · 890 Bytes
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
/*
* tcpHander.h
*
* Created on: 4 Jul 2012
* Author: thomas
*/
#ifndef TCPHANDER_H_
#define TCPHANDER_H_
#include <string>
#include <sstream>
#include <iostream>
#include <boost/asio.hpp>
class TcpHandler
{
public:
TcpHandler(int senderPort)
: acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), senderPort))
{
}
void sendData(const unsigned char * data, const int size)
{
boost::asio::ip::tcp::socket socket(io_service);
acceptor.accept(socket);
boost::system::error_code ignored_error;
boost::asio::write(socket, boost::asio::buffer(data, size), boost::asio::transfer_all(), ignored_error);
}
private:
boost::asio::io_service io_service;
boost::asio::ip::tcp::acceptor acceptor;
};
#endif /* TCPHANDER_H_ */