G
G
German2019-02-19 20:00:03
C++ / C#
German, 2019-02-19 20:00:03

Issues with socket.async_accept() in boost::asio?

I am writing an asynchronous TCP server

#include <iostream>
#include <boost/asio.hpp>
#include <string>
#include <clocale>

using namespace boost::asio;
using namespace std;

class tcp_server
{
private:
  ip::tcp::socket socket;
  ip::tcp::acceptor acceptor;
  int clientCount = 0;
  int port = 0;
  enum { max_lenght = 256 };
  char buff[max_lenght];
public:
  tcp_server(io_service& service, int port) : socket(service), acceptor(
    service,
    ip::tcp::endpoint(ip::tcp::v4(), port))
  {
    this->port = port;
  }
  void do_accept()
  {
    acceptor.async_accept(socket, accept_handler);
  }
  void accept_handler(const boost::system::error_code& error)
  {
    if (!error)
    {
      // Accept succeeded.
    }
  }
};

int main(int argc, char *argv[])
{
  try
  {
    setlocale(LC_ALL, "Rus");
    io_service service;
    tcp_server(service, 5000);
    service.run();
  }
  catch (exception& ex)
  {
    cout << "Исключение: " << ex.what();
    system("pause");
  }
  return 0;
}

Here, I get a bunch of errors.
RBtGE.png
How to fix?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question