-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cpp
More file actions
97 lines (79 loc) · 2.19 KB
/
server.cpp
File metadata and controls
97 lines (79 loc) · 2.19 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Gray Marchese
* Adam Waggoner
* Logan Ropelato
* Jaden Holladay
* Team: Alpha Squad
* CS 3505 Spring 2017
* University of Utah
*
*
* Asychronous TCP server
* This code was originally based on the
* async_tcp_echo_server written and copywrited by 2Christopher M. Kohlhoff (chris at kohlhoff dot com) 2003-2015
* made available publicly through GitHub.
* No infringement or plagiarism is intended through the use of this code, it simply provided our team with a solid
* starting point for our project.
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/
#include <cstdlib>
#include <iostream>
#include <memory>
#include <utility>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include "SpreadsheetManager.h"
#include "Session.h"
// Using the boost asio tcp ip namespaces?
using boost::asio::ip::tcp;
class server
{
public:
server(boost::asio::io_service& io_service, short port)
: acceptor_(io_service, tcp::endpoint(tcp::v4(), port)),
socket_(io_service)
{
do_accept();
SpreadsheetManager::GetInstance();
}
private:
void do_accept()
{
acceptor_.async_accept(socket_, [this](boost::system::error_code ec)
{
if (!ec)
{
std::make_shared<Session>(std::move(socket_))->Start();
}
do_accept();
});
}
tcp::acceptor acceptor_;
tcp::socket socket_;
};
// Hard code the port into the server for this assignment
const int ourPort = 2112;
/*
* Main - Here is where the service is 'created' and started up
*/
int main(int argc, char* argv[])
{
// Declaration of the io_service
boost::asio::io_service io_service;
// Create the server with the io_service variable and the port number
server s(io_service, ourPort);
// Run the server in a new thread
boost::thread bt(boost::bind(&boost::asio::io_service::run, &io_service));
std::string input = "";
while (input != "exit")
{
input = "";
std::cin >> input;
}
io_service.stop();
SpreadsheetManager::GetInstance()->Close();
std::cout <<"Closing the program..." << std::endl;
return 0;
}