Skip to content

Commit 0575e41

Browse files
committed
first-commit
0 parents  commit 0575e41

File tree

13 files changed

+356
-0
lines changed

13 files changed

+356
-0
lines changed

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# TADS-CHAT
2+
## Atividade da disciplina de sistemas distribuídos - TADS19
3+
### Chat feito na linguagem de programação Java - utilizando comunicação TCP (cliente-servidor) com multi-threads e sockets
4+
2.45 KB
Binary file not shown.
2.17 KB
Binary file not shown.
3.87 KB
Binary file not shown.

src/chat/Client.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package chat;
2+
3+
import java.io.*;
4+
import java.net.Socket;
5+
import java.util.Scanner;
6+
7+
/**
8+
* @author Neto
9+
* Configurações do Cliente do Server socket
10+
*/
11+
public class Client implements Runnable{
12+
13+
private Socket conexao;
14+
private Scanner scanner;
15+
private ClientSocket clientSocket;
16+
17+
public Client() {
18+
scanner = new Scanner(System.in);
19+
}
20+
21+
public void start() throws IOException {
22+
try{
23+
conexao = new Socket(Server.HOST, Server.PORT);
24+
clientSocket = new ClientSocket(conexao);
25+
new Thread(this).start(); // cria a thread
26+
messageLoop();
27+
}finally {
28+
conexao.close();
29+
}
30+
}
31+
32+
@Override
33+
public void run() {
34+
String msg;
35+
while ((msg = clientSocket.getMessage()) != null) {
36+
System.out.println(msg);
37+
}
38+
}
39+
40+
private void messageLoop() throws IOException {
41+
String msg;
42+
do {
43+
System.out.print("Digite sua mensagem ou /exit para sair quando desejar) \n");
44+
msg = scanner.nextLine();
45+
clientSocket.sendMsg(msg); // envia a menssagem
46+
} while (!msg.equalsIgnoreCase("/exit"));
47+
}
48+
public static void main(String[] args) {
49+
try {
50+
Client client = new Client();
51+
client.start();
52+
} catch (IOException e) {
53+
System.out.println("Erro no cliente" + e.getMessage());
54+
}
55+
System.out.println("Cliente finalizado");
56+
}
57+
}

0 commit comments

Comments
 (0)