Created
June 17, 2010 01:33
-
-
Save thiagodiogo/441538 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
public void iniciaCliente(){ | |
try { | |
System.out.print("\nCliente tentando conectar com oservidor..."); | |
client = new Socket(enderecoDoServidor, porta); | |
System.out.print("\n Conexão estabelecida..."); | |
in = new DataInputStream((client.getInputStream())); | |
out = new DataOutputStream(client.getOutputStream()); | |
//Enviando a hora agora (T1) | |
out.writeUTF(String.valueOf(System.currentTimeMillis())); | |
msgEntrada = in.readUTF(); | |
System.out.println("\nMensagem recebida em (T4):" + System.currentTimeMillis()); | |
System.out.print("\nMensagem do servidor: "+msgEntrada); | |
in.close(); | |
out.close(); | |
client.close(); | |
} | |
catch (Exception e){ | |
System.out.print("\nErro!"); | |
} | |
} |
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
public void iniciaServidor() { | |
try{ | |
server = new ServerSocket(porta); | |
System.out.print("\nServidor aguardando conexão..."); | |
socket = server.accept(); | |
System.out.print("\n Conexão estabelecida..."); | |
in = new DataInputStream((socket.getInputStream())); | |
out = new DataOutputStream(socket.getOutputStream()); | |
msgEntrada = in.readUTF(); | |
System.out.print("\nT1 recebido do cliente: "+msgEntrada); | |
System.out.println("\nT1 recebida em:" + System.currentTimeMillis()); | |
//Enviando a hora do servidor para o cliente | |
System.out.print("\nT3 enviando ao cliente em: " + System.currentTimeMillis()); | |
out.writeUTF(String.valueOf(System.currentTimeMillis())); | |
in.close(); | |
out.close(); | |
socket.close(); | |
server.close(); | |
} | |
catch ( Exception e ){ | |
System.out.print("\nErro"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment