| 1 | // |
|---|---|
| 2 | // dict.cpp |
| 3 | // |
| 4 | // This sample demonstrates the StreamSocket and SocketStream classes. |
| 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 | #include "Poco/Net/StreamSocket.h" |
| 14 | #include "Poco/Net/SocketStream.h" |
| 15 | #include "Poco/Net/SocketAddress.h" |
| 16 | #include "Poco/StreamCopier.h" |
| 17 | #include "Poco/Path.h" |
| 18 | #include "Poco/Exception.h" |
| 19 | #include <iostream> |
| 20 | |
| 21 | |
| 22 | using Poco::Net::StreamSocket; |
| 23 | using Poco::Net::SocketStream; |
| 24 | using Poco::Net::SocketAddress; |
| 25 | using Poco::StreamCopier; |
| 26 | using Poco::Path; |
| 27 | using Poco::Exception; |
| 28 | |
| 29 | |
| 30 | int main(int argc, char** argv) |
| 31 | { |
| 32 | const std::string HOST("dict.org"); |
| 33 | const unsigned short PORT = 2628; |
| 34 | |
| 35 | if (argc != 2) |
| 36 | { |
| 37 | Path p(argv[0]); |
| 38 | std::cout << "usage: "<< p.getBaseName() << " <term>"<< std::endl; |
| 39 | std::cout << " looks up <term> in dict.org and prints the results"<< std::endl; |
| 40 | return 1; |
| 41 | } |
| 42 | std::string term(argv[1]); |
| 43 | |
| 44 | try |
| 45 | { |
| 46 | SocketAddress sa(HOST, PORT); |
| 47 | StreamSocket sock(sa); |
| 48 | SocketStream str(sock); |
| 49 | |
| 50 | str << "DEFINE ! "<< term << "\r\n"<< std::flush; |
| 51 | str << "QUIT\r\n"<< std::flush; |
| 52 | |
| 53 | sock.shutdownSend(); |
| 54 | StreamCopier::copyStream(str, std::cout); |
| 55 | } |
| 56 | catch (Exception& exc) |
| 57 | { |
| 58 | std::cerr << exc.displayText() << std::endl; |
| 59 | return 1; |
| 60 | } |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 |