Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- public class DictClient {
- public static final String SERVER = "dict.org";
- public static final int PORT = 2628;
- public static final int TIMEOUT = 15000;
- public static void main(String[] args) {
- Socket socket = null;
- try {
- args = new String[1];
- args[0] = "university";
- socket = new Socket(SERVER, PORT);
- socket.setSoTimeout(TIMEOUT);
- OutputStream out = socket.getOutputStream();
- Writer writer = new OutputStreamWriter(out);
- writer = new BufferedWriter(writer);
- InputStream in = socket.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- for (String word : args) {
- define(word, writer, reader);
- }
- writer.write("quit\r\n");
- writer.flush();
- } catch (IOException ex) {
- System.err.println(ex);
- } finally { // dispose if (socket != null) {
- try {
- socket.close();
- } catch (IOException ex) { // ignore
- }
- }
- }
- static void define(String word, Writer writer, BufferedReader reader)
- throws IOException, UnsupportedEncodingException {
- writer.write("DEFINE fd-eng-fra " + word + "\r\n");
- writer.flush();
- try{
- for (String line = reader.readLine(); line != null ; line = reader.readLine()) {
- System.out.println(line);
- if (line.contains("250 ok") || line.contains("552 no match")) break;
- }
- } catch(Exception e){
- System.out.println("Connection timed out");
- }
- }
- }
Add Comment
Please, Sign In to add comment