Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package echoclient;
- import java.io.*;
- import java.net.*;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- public class EchoClient {
- public static void main(String[] args) throws IOException {
- try (
- Socket echoSocket = new Socket("194.47.44.118", 8000);
- PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true);
- BufferedReader in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
- BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));) {
- String userInput;
- String serverInput;
- while (true) {
- userInput = stdIn.readLine();
- String[] sArray = userInput.split(" ");
- if (sArray.length > 1){
- if (sArray[0].equals("dl")) {
- out.println(userInput);
- FileOutputStream fos = new FileOutputStream(sArray[1]);
- BufferedOutputStream fout = new BufferedOutputStream(fos);
- byte[] buffer = new byte[1024];
- int count = 0;
- InputStream fin = echoSocket.getInputStream();
- System.out.println(sArray[1] + buffer.length);
- while ((count = fin.read(buffer)) > 0) {
- fos.write(buffer, 0, count);
- }
- break;
- }}
- for(int i = 0; i<1; i++) {
- StringBuilder sb = new StringBuilder();
- out.println(userInput);
- serverInput = in.readLine();
- sb.append(serverInput);
- if (serverInput.contains("CRLF")) {
- sb.append(System.getProperty(("line.separator")));
- }
- System.out.print(sb);
- }
- }
- } catch (UnknownHostException e) {
- System.err.println("Don't know about host ");
- System.exit(1);
- } catch (IOException e) {
- e.printStackTrace();
- System.err.println("Couldn't get I/O for the connection to ");
- System.exit(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement