Created
June 6, 2017 11:59
-
-
Save joffilyfe/de45c550aba14f90db0e154f83c0c8ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Chat; | |
import java.io.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.IOException; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
import java.util.Scanner; | |
public class Server { | |
public static void main(String[] args) throws IOException { | |
ServerSocket servidor = new ServerSocket(7171, 10); | |
Client cliente1 = new Client("localhost", 7171); | |
cliente1.start(); | |
for (int i = 0; i < 10; i++) { | |
Socket socket = servidor.accept(); | |
int contadorDeMensagens = 1; | |
while(socket.isConnected()) { | |
DataInputStream in = new DataInputStream(socket.getInputStream()); | |
DataOutputStream out = new DataOutputStream(socket.getOutputStream()); | |
System.out.println("[Servidor] Recebendo mensagem: " + in.readUTF()); | |
out.writeUTF("[Servidor] Enviando mensagem " + contadorDeMensagens + "!"); | |
contadorDeMensagens++; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment