Client Java 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

C:\Users\dinar\Downloads\Client.

java 1
1 import java.lang.*;
2 import java.io.*;
3 import java.net.*;
4
5 public class Client {
6 public static void main(String[] args) {
7 try {
8 Socket s = new Socket(args[0], Integer.parseInt(args[1]));
9 BufferedReader netIn = new BufferedReader(new InputStreamReader
(s.getInputStream(), "UTF-8"));
10 BufferedWriter netOut = new BufferedWriter(new OutputStreamWriter
(s.getOutputStream(), "UTF-8"));
11 BufferedReader localIn = new BufferedReader(new InputStreamReader
(System.in));
12
13 while (true) {
14 System.out.println("Inserisci mese (YYYYMM):" );
15 String mese = localIn.readLine();
16 if (mese.equals("fine")) {
17 System.out.println("Termino");
18 break;
19 }
20
21 System.out.println("Inserisci categoria spese:" );
22 String categoria = localIn.readLine();
23
24 System.out.println("Inserisci numero di spese:" );
25 String numero = localIn.readLine();
26
27 netOut.write(mese);
28 netOut.newLine();
29 netOut.write(categoria);
30 netOut.newLine();
31 netOut.write(numero);
32 netOut.newLine();
33
34 netOut.flush();
35
36 while (true) {
37 String line;
38
39 line = netIn.readLine();
40
41 if (line.equals("--- END REQUEST ---"))
42 break;
43
44 System.out.println(line);
45 }
46 }
47
48 s.close();
49 } catch (Exception e) {
50 System.err.println(e.getMessage());
C:\Users\dinar\Downloads\Client.java 2
51 e.printStackTrace(System.err);
52 System.exit(1);
53 }
54 }
55 }
56

You might also like