52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#include <iostream>
|
|
#include <thread>
|
|
#include "chat_networking.hpp"
|
|
|
|
|
|
|
|
struct receive_policy_stdout
|
|
{
|
|
static void message_do_what(chat::chat_message msg)
|
|
{ std::cout << msg.get_content() << '\n'; }
|
|
|
|
static void handshake_do_what(chat::chat_message msg)
|
|
{ std::cout << "Handshake üzenetek:\n" << msg.get_content() << '\n'; }
|
|
|
|
static void serverdirection_do_what(chat::chat_message msg)
|
|
{ std::cout << "Szerver üzenet: " << msg.get_content() << '\n'; }
|
|
|
|
static void login_do_what(chat::chat_message msg)
|
|
{ std::cout << msg.get_content() << " belépett.\n"; }
|
|
|
|
static void logout_do_what(chat::chat_message msg)
|
|
{ std::cout << msg.get_content() << " kilépett.\n"; }
|
|
};
|
|
|
|
|
|
int main()
|
|
{
|
|
boost::asio::io_service ios;
|
|
boost::asio::ip::tcp::resolver resolver(ios);
|
|
boost::asio::ip::tcp::resolver::query query("infoc.eet.bme.hu", "8888");
|
|
auto epit = resolver.resolve(query);
|
|
|
|
|
|
chat::client_network_manager<receive_policy_stdout> cnm(ios, epit, "BATMAN");
|
|
std::thread t([&ios]{ ios.run(); });
|
|
|
|
|
|
std::string input;
|
|
while (true)
|
|
{
|
|
std::cin >> input;
|
|
if (input == "exit")
|
|
break;
|
|
|
|
chat::chat_message msg(chat::message::MESSAGE, input);
|
|
cnm.send(msg);
|
|
}
|
|
|
|
cnm.close_connection();
|
|
t.join();
|
|
}
|