int BfcpService::start(enum ns__AddrFamily af, unsigned short port, bool enbaleConnectionThread, int workThreadNum, double userObsoletedTime, enum ns__ErrorCode *errorCode) { LOG_INFO << "start {af:" << (af == kIPv4 ? "IPv4" : "IPv6") << ", port: " << port << ", enableConnectionThread: " << (enbaleConnectionThread ? "true" : "false") << ", workThreadNum: " << workThreadNum << ", userObsoletedTime: " << userObsoletedTime << "}"; if (server_) { LOG_WARN << "Server already start"; *errorCode = ns__ErrorCode::kServerAlreadyStart; return SOAP_OK; } if (!loop_) { loop_ = thread_.startLoop(); } muduo::net::InetAddress listenAddr((af == kIPv4 ? AF_INET : AF_INET6), port); server_ = boost::make_shared<bfcp::BaseServer>(loop_, listenAddr); if (enbaleConnectionThread) server_->enableConnectionThread(); server_->setWorkerThreadNum(workThreadNum); server_->start(); *errorCode = ns__ErrorCode::kNoError; return SOAP_OK; }
int main() { LOG_INFO << "pid = " << getpid(); dbdky::port::EventLoop loop; dbdky::port::InetAddress listenAddr(2007); EchoServer server(&loop, listenAddr); server.start(); loop.loop(); }
int main(int argc, const char *argv[]) { LOG_INFO << "pid = " << getpid(); muduo::net::EventLoop loop; muduo::net::InetAddress listenAddr(8888); EchoServer server(&loop, listenAddr); server.start(); loop.loop(); return 0; }
int main() { EventLoop baseLoop; InetAddress listenAddr("127.0.0.1", 8888); std::unique_ptr<TcpServer> tcpServer(new TcpServer(&baseLoop, listenAddr, "test")); tcpServer->setMessageCallback(std::move(onMessage)); tcpServer->start(); baseLoop.loop(); return 0; }
void test_acceptor() { printf("main(): pid = %d, tid = %d\n", getpid(), this_thread::get_id().value()); InetAddress listenAddr(8888); EventLoop loop; TcpAcceptor acceptor(&loop, listenAddr); acceptor.setNewConnectionCallback(newConnection); acceptor.listen(); loop.loop(); }
int main(int argc, char* argv[]) { EventLoop loop; InetAddress listenAddr(10000); TcpServer server(&loop, listenAddr); server.SetConnectionCallBack(onConnection); server.SetMessageCallBack(onMessage); if (argc > 1) { server.SetThreadNum(atoi(argv[1])); } server.Start(); loop.Loop(); }
int main(int argc,char **argv) { muduo::net::EventLoop loop; g_loop = &loop; uint16_t port = 6666; muduo::net::InetAddress listenAddr("127.0.0.1",port); muduo::net::Acceptor acceptor(g_loop,listenAddr,true); acceptor.listen(); acceptor.setNewConnectionCallback(cb1); //设置新回调 loop.loop(); //开始循环 return 0; }
int main(int argc, const char *argv[]) { printf("main(): pid = %d\n", getpid()); muduo::InetAddress listenAddr(9981); muduo::EventLoop loop; muduo::TcpServer server(&loop, listenAddr, "discard"); server.setConnectionCallback(onConnection); server.setMessageCallback(onMessage); if(argc > 1){ server.setThreadNum(atoi(argv[1])); } server.start(); loop.loop(); return 0; }
void pixel_styles_controller::run() { mUdpSocket = new udp_socket(UDP_BROADCAST_PORT); mModesController->active_mode()->initialize(mStaticColors); mAliveTimer->run(); mPaintTimer->run(); mPreviewTimer->run(); muduo::net::InetAddress listenAddr(TCP_CONNECTION_PORT); int maxConnections = 5; LOG_DEBUG << "maxConnections = " << maxConnections; mTcpServer = new tcp_server(get_global_event_loop(), listenAddr, maxConnections); mModesController->set_tcp_server(mTcpServer); mTcpServer->register_read_callback(bind(&pixel_styles_controller::handle_tcp_request, this, _1, _2)); mTcpServer->run(); }
int main(int argc, const char *argv[]) { printf("main(): pid = %d\n", getpid()); muduo::InetAddress listenAddr(9981); muduo::InetAddress listenAddr1(8888); muduo::EventLoop loop; muduo::Acceptor acceptor(&loop, listenAddr); acceptor.setNewConnectionCallback(newConnection9981); acceptor.listen(); muduo::Acceptor acceptor1(&loop, listenAddr1); acceptor1.setNewConnectionCallback(newConnection8888); acceptor1.listen(); loop.loop(); return 0; }
int main() { string line; for (int i = 33; i < 127; i++) { line.push_back(char(i)); } line += line; for (size_t i = 0; i < 127 - 33; ++i) { message += line.substr(i, 72) + '\n'; } cout << message << endl << endl; Logger::setLogLevel(Logger::TRACE); InetAddress listenAddr(9981); EventLoop loop; TcpServer server(&loop, listenAddr, "tcpservertest"); server.setConnectionCallback(onConnection); server.setMessageCallback(onMessage); server.setWriteCompleteCallback(onWriteComplete); server.start(); loop.loop(); }
int main(void){ LOG_INFO << "pid = " << getpid(); std::string mIpAddress, mUsername, mPassword, mPort; int mMaxConnection; unsigned short sPort; int sMaxConnection; const char ConfigFile[] = "CommodityServer.conf"; Config configSettings(ConfigFile); mIpAddress = configSettings.Read("mIpAddress", mIpAddress); mUsername = configSettings.Read("mUsername", mUsername); mPassword = configSettings.Read("mPassword", mPassword); mPort = configSettings.Read("mPort", mPort); configSettings.ReadInto(sPort, "sPort"); mMaxConnection = configSettings.Read("mMaxConnection", 0); configSettings.ReadInto(sMaxConnection, "sMaxConnection"); // std::cout << configSettings; string name = "Search"; shared_ptr<CommoditySearch> ptr = shared_ptr<CommoditySearch>(new CommoditySearch()); BaseFactory::RegisterInstanceIntoMap(name, ptr); ConnectionPool *connPool = ConnectionPool::GetInstance("tcp://" + mIpAddress + ":" + mPort, mUsername, mPassword, mMaxConnection); if(!connPool){ LOG_INFO << "Construct a MySQL connection pool fail...."; return -1; } muduo::net::EventLoop loop; muduo::net::InetAddress listenAddr(sPort); CommodityServer server(&loop, listenAddr); // server.setThreadNum(sMaxConnection); server.start(); loop.loop(); return 0; }