-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
48 lines (37 loc) · 1.34 KB
/
Copy pathClient.java
File metadata and controls
48 lines (37 loc) · 1.34 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
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class Client{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
try {
Socket s = new Socket("localhost", 6969);
DataInputStream in = new DataInputStream(s.getInputStream());
DataOutputStream out = new DataOutputStream(s.getOutputStream());
String fromserver;
String mode;
String fromuser;
while (true) {
mode = in.readUTF();
if (mode.equals("break")) break;
fromserver = in.readUTF();
if (!fromserver.isEmpty())
System.out.println(fromserver);
if (mode.equals("write")) {
fromuser = sc.nextLine();
out.writeUTF(fromuser);
}
if (mode.equals("read")) {
}
sc.close();
s.close();
}
}catch (ConnectException connectException){
System.out.println("Erro ao conectar ao servidor");
}catch (SocketException socketException){
System.out.println("Ouve um erro no servidor, o servidor provavelmente caiu");
}catch (Exception e){
System.out.println("Ouve um erro desconhecido");
}
}
}