Advertisement
syedislam

Untitled

Nov 14th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1.  
  2. import java.io.*;
  3. import java.net.*;
  4.  
  5. public class DictClient {
  6. public static final String SERVER = "dict.org";
  7. public static final int PORT = 2628;
  8. public static final int TIMEOUT = 15000;
  9.  
  10. public static void main(String[] args) {
  11. Socket socket = null;
  12. try {
  13.  
  14. args = new String[1];
  15. args[0] = "university";
  16.  
  17. socket = new Socket(SERVER, PORT);
  18. socket.setSoTimeout(TIMEOUT);
  19. OutputStream out = socket.getOutputStream();
  20. Writer writer = new OutputStreamWriter(out);
  21. writer = new BufferedWriter(writer);
  22. InputStream in = socket.getInputStream();
  23. BufferedReader reader = new BufferedReader(new InputStreamReader(in));
  24. for (String word : args) {
  25. define(word, writer, reader);
  26. }
  27. writer.write("quit\r\n");
  28. writer.flush();
  29. } catch (IOException ex) {
  30. System.err.println(ex);
  31. } finally { // dispose if (socket != null) {
  32. try {
  33. socket.close();
  34. } catch (IOException ex) { // ignore
  35. }
  36. }
  37. }
  38.  
  39. static void define(String word, Writer writer, BufferedReader reader)
  40. throws IOException, UnsupportedEncodingException {
  41. writer.write("DEFINE fd-eng-fra " + word + "\r\n");
  42. writer.flush();
  43. try{
  44. for (String line = reader.readLine(); line != null ; line = reader.readLine()) {
  45. System.out.println(line);
  46. if (line.contains("250 ok") || line.contains("552 no match")) break;
  47. }
  48. } catch(Exception e){
  49. System.out.println("Connection timed out");
  50. }
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement