Como faço para conectar um cliente a um servidor via internet usando Corba e Java!! Tenho que usar o protocolo IIOP?
Este é meu cliente!import java.io.*;
import java.util.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import java.net.*;
public class FileClient {
public static void main(String argv[])
{
try
{
// Crea e inicializa el ORB
ORB orb = ORB.init(argv, null);
// Obtiene el contexto de nombrado raiz
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// Resuelve la referencia al objeto en el nombrado
NameComponent nc = new NameComponent("FileTransfer", "");
NameComponent path[] = {nc};
FileInterface helloRef = FileInterfaceHelper.narrow(orb.string_to_object("corbaname:iiop:1.2@localhost#FileTransfer"));
//ncRef.resolve(path));
// Llama al objeto servidor Hello e imprime el resultado
if(argv.length < 1)
{
System.out.println("Usar: java ArquivoCliente NomedoArquivo");
}
String hostName =new String(InetAddress.getLocalHost().toString());
// save the file
long startTime = System.currentTimeMillis();
File file = new File("C:\\" + argv[0]);
byte data[] = helloRef.downloadFile(argv[0], hostName);
BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(file));
// Criando a copia do arquivo a ser recebido do servidor
System.out.println("Tamanho do arquivo " +data.length);
// Salvando no disco
output.write(data, 0, data.length);
output.flush();
output.close();
long stopTime = System.currentTimeMillis();
System.out.println("Tempo em msecs = "+ (stopTime - startTime));
}
catch(Exception e)
{
System.out.println("FileClient Error: " + e.getMessage());
e.printStackTrace();
}
}
}
Favor Sempre usar a tag Code para incluir códigos!