Ver Mensaje Individual
  #1  
Antiguo 21-03-2008
maro maro is offline
Miembro
 
Registrado: sep 2003
Ubicación: Sevilla
Posts: 104
Reputación: 21
maro Va por buen camino
usar upnp con Delphi para configurar nat en un router?

Hola,

He leído en algunas páginas, por Internet, que utilizando upnp es posible añadir un registro a la tabla de nat del router, de tal forma que un programa que contenga un servidor tcp pueda "escuchar" de forma transparente, sin que el usuario tenga que configurar el router o firewall.

Incluso he encontrado este código:
Código Delphi [-]
Procedure AddUPnPEntry( Port : Integer;  const Name : ShortString);
Var
  Nat   : Variant;
  Ports : Variant;
Begin
  if NOT (LAN_IP = '127.0.0.1') then
  begin
    try
      Nat := CreateOleObject('HNetCfg.NATUPnP');
      Ports := Nat.StaticPortMappingCollection;
                        showMessage(inttostr(Ports.count));
      Ports.Add(port, 'TCP', port, LAN_IP, True, name);
    except
      ShowMessage(
        'An Error occured with adding UPnP Ports. The ' + name +
        ' port was not added to the router.  Please check to see if your ' +
        'router supports UPnP and has it enabled or disable UPnP.'
      );
    end;
    {[2006/03/04] CR - I'd looked into other ways to handle errors, but,
     unfortunately the try-except Alex used here originally is the ONLY way
     to trap errors.  OLE/.COM bites, if you have to rely on exceptions all the
     time! :P~~ }
  end;
End; { Proc AddUPnPEntry}

pero no consigo que funcione.

¿Alguén sabe algo sobre este tema?

Muchas gracias.
Un Saludo.
__________________
Maro. OutSourcing de programación con Delphi.
Responder Con Cita