Skip to content

Instantly share code, notes, and snippets.

@gusthavosouza
Created April 20, 2016 00:00
Show Gist options
  • Save gusthavosouza/d384163aca943384ad0adfa498561d11 to your computer and use it in GitHub Desktop.
Save gusthavosouza/d384163aca943384ad0adfa498561d11 to your computer and use it in GitHub Desktop.
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