Skip to content

Instantly share code, notes, and snippets.

@thiagodiogo
Created June 17, 2010 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagodiogo/441538 to your computer and use it in GitHub Desktop.
Save thiagodiogo/441538 to your computer and use it in GitHub Desktop.
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!");
}
}
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