Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.Socket;
- public class Cliente extends Thread {
- DataOutputStream outStream = null;
- DataInputStream inStream = null;
- Socket socket = null;
- String msgSnd = "";
- BufferedReader teclado = null;
- public Cliente() {
- super();
- }
- public void run() {
- teclado = new BufferedReader(new InputStreamReader(System.in));
- try {
- socket = new Socket("localhost", 22350);
- outStream = new DataOutputStream(socket.getOutputStream());
- inStream = new DataInputStream(socket.getInputStream());
- System.out.println("instanciou os DataStream");
- new Thread(){
- {
- setName("pooler-leitura-server");
- }
- public void run() {
- try {
- String msg = "a";
- while(true) {
- System.out.println("entrou no while de leitura");
- msg = inStream.readUTF();
- System.out.println("server: " + msg + "");
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- };
- }.start();
- while(true) {
- msgSnd = teclado.readLine();
- outStream.writeUTF(msgSnd);
- outStream.flush();
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static void main(String args[]) {
- Cliente c = new Cliente();
- c.setPriority(Thread.MAX_PRIORITY);
- c.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement