Biblioteca Java - Blame information for rev 3

Subversion Repositories:
Rev:
Rev Author Line No. Line
3 mihai 1 /*
2  * ClientSimplu.java
3  */
4  
5 /**
6  * Class created by @author Mihai HULEA at Feb 23, 2005.
7  *
8  * This class is part of the laborator2_serverclientmonofir project.
9  *
10  * 1. Modificati aplicatia client astfel incat aceasta sa trimita catre server mesaje
11  * citite de la tastatura.
12  */
13 package lab.scd.net.socket;
14 import java.net.*;
15 import java.io.*;
16  
17 public class ClientSimplu {
18  
19   public static void main(String[] args)throws Exception{
20     Socket socket=null;
21     try {
22       //creare obiect address care identifica adresa serverului
23       InetAddress server_address =InetAddress.getByName("localhost");
24       //se putea utiliza varianta alternativa: InetAddress.getByName("127.0.0.1")
25  
26       socket = new Socket(server_address,1900);
27  
28       //construieste fluxul de intrare prin care sunt receptionate datele de la server
29       BufferedReader in =
30         new BufferedReader(
31           new InputStreamReader(
32             socket.getInputStream()));
33  
34       //construieste fluxul de iesire prin care datele sunt trimise catre server
35       // Output is automatically flushed
36       // by PrintWriter:
37       PrintWriter out =
38         new PrintWriter(
39           new BufferedWriter(
40             new OutputStreamWriter(
41               socket.getOutputStream())),true);
42  
43  
44       for(int i = 0; i < 10; i ++) {
45         out.println("mesaj " + i);
46         out.flush();
47  
48         String str = in.readLine(); //trimite mesaj
49         System.out.println(str); //asteapta raspuns
50       }
51       out.println("END"); //trimite mesaj care determina serverul sa inchida conexiunea
52  
53     }
54     catch (Exception ex) {ex.printStackTrace();}
55     finally{
56       socket.close();
57     }
58   }
59 }
60