-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.h
37 lines (31 loc) · 1.11 KB
/
Server.h
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
#ifndef SERVER
#define SERVER
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <fstream>
#include <vector>
#include <iostream>
// Class to start a network communication as a server
class Server {
public:
// initiates the network stack on the given port
Server(boost::asio::io_context& io_context, int port);
// wait until data is received from the client
int receive(std::string& msg);
// receive data and close socket
int receive_data(std::string& msg);
// receive for binary data
int receive_file(const std::string& filename);
// send data to the client
int send(std::string msg);
// send binary data to the client
int send_file(const std::string& filename);
private:
// provides all i/o functionality
boost::asio::io_context& io_context_;
// functionality to accept incoming connections
boost::asio::ip::tcp::acceptor acceptor_;
// socket used for the connection
boost::asio::ip::tcp::socket socket_;
};
#endif // SERVER