-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
33 lines (25 loc) · 827 Bytes
/
main.cpp
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
#include "tcpserver.h"
#include <iostream>
using namespace cpptcp;
class MyTcpServer : public TcpServer
{
public:
MyTcpServer(uint16_t port) : TcpServer(port){}
~MyTcpServer() {}
virtual void onConnect(std::shared_ptr<Session> pSession) override {
std::cout << "client " << pSession->address() << " is connect" << std::endl;
}
virtual void onClose(const std::string & address) override {
std::cout << "client " << address << " is closed" << std::endl;
}
virtual void onMessage(const std::string &message, std::shared_ptr<Session> pSession) override {
std::cout << "Recv client " << pSession->address() << " message:" << message << std::endl;
pSession->async_send_msg(message);
}
};
int main()
{
MyTcpServer server(8000);
server.start();
return 0;
}