Hello,
I have created a simple server application. It listens on a port for the client to send.
However, I have implemented a loop, so that the server will always be listening.
However, is there a better way like using a event, so when a message is received it will fire the event. Instead of using a while loop.
Many thanks,
Here is my code:
Code:try { Poco::Net::SocketAddress addr("PiyaLim", 6000); Poco::Net::DatagramSocket sock; sock.bind(addr); while(true) { char buffer[256] = {0}; sock.receiveFrom(buffer,sizeof(buffer), addr); std::string message = buffer; int strLength = 0; strLength = message.length(); message = message.substr(0,strLength); std::cout << "*********************** START ***********************************************" << std::endl; std::cout << "The message is: " << message << " The length of the string is: " << strLength << std::endl; std::cout << "Address: " << addr.host().toString() << std::endl; std::cout << "Port Number: " << addr.port() << std::endl; std::cout << "*********************** END *************************************************" << std::endl; } } catch(Poco::Exception ex) { std::cout << ex.message(); std::cin.get(); }




Reply With Quote