Biblioteca Java - Blame information for rev 3

Subversion Repositories:
Rev:
Rev Author Line No. Line
3 mihai 1 package lab.scd.securecomm;
2  
3 import java.io.*;
4 import java.net.InetAddress;
5 import java.net.InetSocketAddress;
6 import java.net.ServerSocket;
7 import java.net.Socket;
8 import java.net.SocketAddress;
9  
10  
11 public class SServer {
12         public static void main(String[] args) throws IOException{
13  
14             ServerSocket ss=null;
15             Socket s=null;
16  
17             try{
18               String line="";
19               ss = new ServerSocket(1900); //creaza obiectul serversocket
20               System.out.println("Serverul asteapta conexiuni...");
21               s = ss.accept(); //incepe asteptarea de conexiuni  pe portul 1900
22               //in momentul in care un client s-a  conectat ss.accept() returneaza
23               //un obiect de tip Socket care identifica conexiunea
24  
25               //creaza fluxurile de intrare iesire
26               BufferedReader in = new BufferedReader(
27                     new InputStreamReader(s.getInputStream()));
28  
29               PrintWriter out = new PrintWriter(
30                     new BufferedWriter(new OutputStreamWriter(
31                       s.getOutputStream())),true);
32  
33               //extrage adresa de ip si portul de pe care clientul s-a conectat
34               InetSocketAddress remoteadr = (InetSocketAddress)s.getRemoteSocketAddress();
35               String remotehost = remoteadr.getHostName();
36               int remoteport = remoteadr.getPort();
37  
38               System.out.println("Client nou conectat: "+remotehost+":"+remoteport);
39  
40               while(!line.equals("END")){
41                 line = in.readLine(); //citeste datele de la client
42                 System.out.println("Server a receptionat:"+line);
43                 out.println("ECHO "+line); //trimite date la client
44                 out.flush();
45               }
46  
47               System.out.println("Aplicatie server gata.");
48  
49             }catch(Exception e){e.printStackTrace();}
50              finally{
51               ss.close();
52               if(s!=null) s.close();
53              }
54           }
55  
56 }