forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict.cpp
More file actions
executable file
·65 lines (54 loc) · 1.34 KB
/
dict.cpp
File metadata and controls
executable file
·65 lines (54 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// dict.cpp
//
// $Id: //poco/1.4/Net/samples/dict/src/dict.cpp#1 $
//
// This sample demonstrates the StreamSocket and SocketStream classes.
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/SocketStream.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/StreamCopier.h"
#include "Poco/Path.h"
#include "Poco/Exception.h"
#include <iostream>
using Poco::Net::StreamSocket;
using Poco::Net::SocketStream;
using Poco::Net::SocketAddress;
using Poco::StreamCopier;
using Poco::Path;
using Poco::Exception;
int main(int argc, char** argv)
{
const std::string HOST("dict.org");
const unsigned short PORT = 2628;
if (argc != 2)
{
Path p(argv[0]);
std::cout << "usage: " << p.getBaseName() << " <term>" << std::endl;
std::cout << " looks up <term> in dict.org and prints the results" << std::endl;
return 1;
}
std::string term(argv[1]);
try
{
SocketAddress sa(HOST, PORT);
StreamSocket sock(sa);
SocketStream str(sock);
str << "DEFINE ! " << term << "\r\n" << std::flush;
str << "QUIT\r\n" << std::flush;
sock.shutdownSend();
StreamCopier::copyStream(str, std::cout);
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
return 0;
}