summaryrefslogtreecommitdiff
path: root/server/tcpserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'server/tcpserver.cpp')
-rw-r--r--server/tcpserver.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/server/tcpserver.cpp b/server/tcpserver.cpp
new file mode 100644
index 0000000..528d1a2
--- /dev/null
+++ b/server/tcpserver.cpp
@@ -0,0 +1,28 @@
+#include "tcpserver.h"
+
+#include <boost/bind.hpp>
+
+TCPServer::TCPServer(boost::asio::io_service& io_service)
+ : acceptor_(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 12345)) {
+
+ // Start listening for first connection attempt.
+ listen();
+}
+
+void TCPServer::listen() {
+ Connection::p new_connection = Connection::create(acceptor_.io_service());
+
+ acceptor_.async_accept(new_connection->socket,
+ boost::bind(&TCPServer::handle_connection, this, new_connection, boost::asio::placeholders::error));
+}
+
+void TCPServer::handle_connection(Connection::p connection, const boost::system::error_code& error) {
+ if(error) {
+ return;
+ }
+
+ connection->connected();
+
+ // Start listening for another connection attempt.
+ listen();
+} \ No newline at end of file