Advertisement
sombriks

mod do cliente do yuri

Feb 6th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.50 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.DataInputStream;
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.net.Socket;
  7.  
  8.  
  9. public class Cliente extends Thread {
  10.     DataOutputStream outStream = null;
  11.     DataInputStream inStream = null;
  12.     Socket socket = null;
  13.     String msgSnd = "";
  14.     BufferedReader teclado = null;
  15.  
  16.     public Cliente() {
  17.         super();
  18.     }
  19.  
  20.     public void run() {
  21.         teclado = new BufferedReader(new InputStreamReader(System.in));
  22.         try {
  23.             socket = new Socket("localhost", 22350);
  24.             outStream = new DataOutputStream(socket.getOutputStream());
  25.             inStream = new DataInputStream(socket.getInputStream());
  26.             System.out.println("instanciou os DataStream");
  27.             new Thread(){
  28.                 {
  29.                     setName("pooler-leitura-server");
  30.                 }
  31.                 public void run() {
  32.                     try {
  33.                         String msg = "a";
  34.                         while(true) {
  35.                             System.out.println("entrou no while de leitura");
  36.                             msg = inStream.readUTF();
  37.                             System.out.println("server: " + msg + "");
  38.                         }
  39.                     } catch (IOException e) {
  40.                         // TODO Auto-generated catch block
  41.                         e.printStackTrace();
  42.                     }
  43.                 };
  44.             }.start();
  45.             while(true) {
  46.                 msgSnd = teclado.readLine();
  47.                 outStream.writeUTF(msgSnd);
  48.                 outStream.flush();
  49.             }
  50.  
  51.         } catch (IOException e) {
  52.             // TODO Auto-generated catch block
  53.             e.printStackTrace();
  54.         }
  55.     }
  56.  
  57.     public static void main(String args[]) {
  58.         Cliente c = new Cliente();
  59.         c.setPriority(Thread.MAX_PRIORITY);
  60.         c.start();
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement