Created
April 20, 2016 00:00
-
-
Save gusthavosouza/d384163aca943384ad0adfa498561d11 to your computer and use it in GitHub Desktop.
This file contains 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 uscs; | |
import java.io.*; | |
import java.net.*; | |
public class Atv01 { | |
@SuppressWarnings("deprecation") | |
public static void main(String args[]) { | |
try { | |
ServerSocket echoServer = new ServerSocket(1234); | |
System.out.println("Servidor Ativo na Porta " + echoServer.getLocalPort()); | |
Socket clientSocket = echoServer.accept(); | |
DataInputStream is = new DataInputStream(clientSocket.getInputStream()); | |
PrintStream os = new PrintStream(clientSocket.getOutputStream()); | |
String line = is.readLine(); | |
os.println("Conectado ao Servidor na Porta 1234"); | |
os.println("Digite qualquer palavra e tecle Enter ou FIM para encerrar..."); | |
boolean recebe = true; | |
while (recebe) { | |
if (line == null || line.trim().equals("FIM")) { | |
recebe = false; | |
} else { | |
System.out.println("Recebido do cliente:" + line); | |
os.println("Enviado do Servidor: " + line); | |
line = is.readLine(); | |
} | |
} | |
echoServer.close(); | |
} catch (IOException e) { | |
System.out.println(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment