-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
74 lines (63 loc) · 1.94 KB
/
Client.java
File metadata and controls
74 lines (63 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.io.*;
import java.net.Socket;
public class Client {
private Socket socketCliente;
private BufferedReader input;
private PrintWriter output;
private BufferedReader inputConfig;
public Client(){
try{
inputConfig= new BufferedReader(new InputStreamReader(System.in));
socketCliente = new Socket(host(), porta());
output = new PrintWriter(socketCliente.getOutputStream(), true);
input = new BufferedReader(new InputStreamReader(socketCliente.getInputStream()));
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
public void write(){
while(true){
try{
String servidorResposta;
String inputUsuario;
while(true){
inputUsuario = inputConfig.readLine();
if(inputUsuario != null){
output.print(inputUsuario);
}
if((servidorResposta = this.input.readLine()) != null){
System.out.println("Server: "+ servidorResposta);
}
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
private String host(){
System.out.println("Diga o host: ");
try{
return inputConfig.readLine();
}
catch(IOException e){
System.out.println(e.getMessage());
}
return "";
}
private int porta(){
System.out.println("Diga a porta: ");
try{
return Integer.parseInt(inputConfig.readLine());
}
catch(IOException e){
System.out.println(e.getMessage());
}
return 8080;
}
public static void main(String[] args){
Client cliente = new Client();
cliente.write();
}
}