Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package echoclient;
  7.  
  8. import java.io.*;
  9. import java.net.*;
  10. import java.nio.file.Path;
  11. import java.nio.file.Paths;
  12.  
  13. public class EchoClient {
  14.  
  15. public static void main(String[] args) throws IOException {
  16.  
  17.  
  18.  
  19. try (
  20. Socket echoSocket = new Socket("194.47.44.118", 8000);
  21. PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true);
  22. BufferedReader in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
  23. BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));) {
  24.  
  25. String userInput;
  26. String serverInput;
  27. while (true) {
  28.  
  29. userInput = stdIn.readLine();
  30.  
  31. String[] sArray = userInput.split(" ");
  32.  
  33. if (sArray.length > 1){
  34. if (sArray[0].equals("dl")) {
  35. out.println(userInput);
  36.  
  37. FileOutputStream fos = new FileOutputStream(sArray[1]);
  38. BufferedOutputStream fout = new BufferedOutputStream(fos);
  39. byte[] buffer = new byte[1024];
  40. int count = 0;
  41.  
  42. InputStream fin = echoSocket.getInputStream();
  43. System.out.println(sArray[1] + buffer.length);
  44.  
  45. while ((count = fin.read(buffer)) > 0) {
  46. fos.write(buffer, 0, count);
  47. }
  48. break;
  49. }}
  50.  
  51. for(int i = 0; i<1; i++) {
  52. StringBuilder sb = new StringBuilder();
  53. out.println(userInput);
  54. serverInput = in.readLine();
  55. sb.append(serverInput);
  56.  
  57. if (serverInput.contains("CRLF")) {
  58. sb.append(System.getProperty(("line.separator")));
  59. }
  60. System.out.print(sb);
  61. }
  62. }
  63. } catch (UnknownHostException e) {
  64. System.err.println("Don't know about host ");
  65. System.exit(1);
  66. } catch (IOException e) {
  67. e.printStackTrace();
  68. System.err.println("Couldn't get I/O for the connection to ");
  69. System.exit(1);
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement