Biblioteca Java - Blame information for rev 3
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
3 | mihai | 1 | package lab.scd.net.chatsimple; |
2 | |||
3 | import java.util.Scanner; | ||
4 | import java.net.*; | ||
5 | import java.io.*; | ||
6 | |||
7 | public class CClient extends Thread { | ||
8 | BufferedReader in; | ||
9 | PrintWriter out; | ||
10 | |||
11 | @Override | ||
12 | public void run() { | ||
13 | try { | ||
14 | Socket s = new Socket("localhost",1999); | ||
15 | |||
16 | out = new PrintWriter(new OutputStreamWriter(s.getOutputStream()),true); | ||
17 | in = new BufferedReader(new InputStreamReader(s.getInputStream())); | ||
18 | |||
19 | while(true){ | ||
20 | String msg = in.readLine(); | ||
21 | System.out.println("rcv:"+msg); | ||
22 | } | ||
23 | } catch (Exception e) { | ||
24 | e.printStackTrace(); | ||
25 | } | ||
26 | } | ||
27 | |||
28 | public void console(){ | ||
29 | Scanner s = new Scanner(System.in); | ||
30 | while(true){ | ||
31 | if(s.hasNextLine()){ | ||
32 | String mesaj = s.nextLine(); | ||
33 | out.println(mesaj); | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | |||
38 | public static void main(String[] args) { | ||
39 | CClient c = new CClient(); | ||
40 | c.start(); | ||
41 | c.console(); | ||
42 | } | ||
43 | } |