| 1 | // |
| 2 | // UDPEchoServer.h |
| 3 | // |
| 4 | // Definition of the UDPEchoServer class. |
| 5 | // |
| 6 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
| 7 | // and Contributors. |
| 8 | // |
| 9 | // SPDX-License-Identifier: BSL-1.0 |
| 10 | // |
| 11 | |
| 12 | |
| 13 | #ifndef UDPEchoServer_INCLUDED |
| 14 | #define UDPEchoServer_INCLUDED |
| 15 | |
| 16 | |
| 17 | #include "Poco/Net/Net.h" |
| 18 | #include "Poco/Net/DatagramSocket.h" |
| 19 | #include "Poco/Net/SocketAddress.h" |
| 20 | #include "Poco/Thread.h" |
| 21 | #include "Poco/Event.h" |
| 22 | |
| 23 | |
| 24 | class UDPEchoServer: public Poco::Runnable |
| 25 | /// A simple sequential UDP echo server. |
| 26 | { |
| 27 | public: |
| 28 | UDPEchoServer(); |
| 29 | /// Creates the UDPEchoServer. |
| 30 | |
| 31 | UDPEchoServer(const Poco::Net::SocketAddress& sa); |
| 32 | /// Creates the UDPEchoServer and binds it to |
| 33 | /// the given address. |
| 34 | |
| 35 | ~UDPEchoServer(); |
| 36 | /// Destroys the UDPEchoServer. |
| 37 | |
| 38 | Poco::UInt16 port() const; |
| 39 | /// Returns the port the echo server is |
| 40 | /// listening on. |
| 41 | |
| 42 | Poco::Net::SocketAddress address() const; |
| 43 | /// Returns the address of the server. |
| 44 | |
| 45 | void run(); |
| 46 | /// Does the work. |
| 47 | |
| 48 | private: |
| 49 | Poco::Net::DatagramSocket _socket; |
| 50 | Poco::Thread _thread; |
| 51 | Poco::Event _ready; |
| 52 | bool _stop; |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | #endif // UDPEchoServer_INCLUDED |
| 57 | |