void EchoServer::onClose(const TcpConnectionPtr &conn) { cout << "client : " << conn->getPeerAddr().toIp() << " : " << conn->getPeerAddr().toPort() << " close" << endl; conn->shutdown(); }
void EchoServer::onConnect(const TcpConnectionPtr &conn) { cout << "client : " << conn->getPeerAddr().toIp() << " : " << conn->getPeerAddr().toPort() << " on" << endl; conn->send("hello, welcome to Echo Server!\r\nenter word to look for, or q to quit: "); }
void AppBusiness::onTcpConnected(const TcpConnectionPtr& connection) { logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)", connection->getPeerAddr().getDisplayStr().c_str(), connection->getServerConnCount()); connection->recv(); }
//----------------------------------------------------------------------------- // 描述: 接受了一个新的TCP连接 //----------------------------------------------------------------------------- void AppBusiness::onTcpConnected(const TcpConnectionPtr& connection) { logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)", connection->getPeerAddr().getDisplayStr().c_str(), connection->getServerConnCount()); string msg = "Welcome to the simple echo server, type 'quit' to exit.\r\n"; connection->send(msg.c_str(), msg.length()); }
void ServerModule_Daytime::onTcpConnected(const TcpConnectionPtr& connection) { logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)", connection->getPeerAddr().getDisplayStr().c_str(), connection->getServerConnCount()); string msg = DateTime::now().toDateTimeString() + "\n"; connection->send(msg.c_str(), msg.length()); }
void ServerModule_Chargen::onTcpConnected(const TcpConnectionPtr& connection) { logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)", connection->getPeerAddr().getDisplayStr().c_str(), connection->getServerConnCount()); connection->setNoDelay(true); connection->recv(); connection->send(message_.c_str(), message_.length()); }
//----------------------------------------------------------------------------- // 描述: 接受了一个新的TCP连接 //----------------------------------------------------------------------------- void AppBusiness::onTcpConnected(const TcpConnectionPtr& connection) { logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)", connection->getPeerAddr().getDisplayStr().c_str(), connection->getServerConnCount()); //string msg = "Welcome to the simple echo server, type 'quit' to exit.\r\n"; //ConnetManager::instance().add(connection); connection->recv(SELF_PACKET_SPLITTER, EMPTY_CONTEXT); }
void AppBusiness::onTcpConnected(const TcpConnectionPtr& connection) { const int MAX_CONN_COUNT = 3; logger().writeFmt("onTcpConnected (%s) (ConnCount: %d)", connection->getPeerAddr().getDisplayStr().c_str(), connection->getServerConnCount()); int connCount = connection->getServerConnCount(); if (connCount > MAX_CONN_COUNT) { logger().writeFmt("Too many connections. (ConnCount: %d)", connCount); connection->disconnect(); } else { string msg = "Welcome to the simple echo server, type 'quit' to exit.\r\n"; connection->send(msg.c_str(), msg.length()); } }
void onConnect(const TcpConnectionPtr &conn) { cout<<"New Client"<<conn->getPeerAddr().toIp()<<"Port" <<conn->getPeerAddr().toPort()<<endl; conn->sendString("hello"); }
void EchoServer::onConnection(const TcpConnectionPtr &conn) { cout << conn->getPeerAddr().toIp() << " port: " << conn->getPeerAddr().toPort() << endl; conn->send("Hello, welcome to Echo Server!!!\r\n"); }