2013-03-10 1 views
6

現在GTAというゲーム用のマッチメーカーを開発中ですが、問題はゲームサーバーが7777ポートを使用しているため、プレイヤーがサーバーに参加できるようにするにはこのポートを全世界に開く必要がありますユーザーがルーターを変更することは望ましくありません。ルーターを使ったルーターポート転送

注:ゲームサーバーは私のものではなく、ソースコードを変更することはできません。起動するだけです。

したがって、私はClingがポート転送で処理できることを発見しましたが、動作させることはできません!

コード私が使用しています:

public static void openports() throws UnknownHostException { 
    InetAddress i = InetAddress.getLocalHost(); 
    System.out.println(i.getHostAddress()); 

    UpnpService upnpServiceTCP = new UpnpServiceImpl(new PortMappingListener(new PortMapping(7777, i.getHostAddress(), PortMapping.Protocol.TCP))); 
    upnpServiceTCP.getControlPoint().search(new STAllHeader()); 

    UpnpService upnpServiceUDP = new UpnpServiceImpl(new PortMappingListener(new PortMapping(7777, i.getHostAddress(), PortMapping.Protocol.UDP))); 
    upnpServiceUDP.getControlPoint().search(new STAllHeader()); 
} 

誰もがそれを動作させるための任意のアイデアを持っていますか?

答えて

5

private void doPortForwarding() { 

     PortMapping[] desiredMapping = new PortMapping[2]; 
     desiredMapping[0] = new PortMapping(8123, InetAddress.getLocalHost().getHostAddress(), 
       PortMapping.Protocol.TCP, " TCP POT Forwarding"); 

     desiredMapping[1] = new PortMapping(8123, InetAddress.getLocalHost().getHostAddress(), 
        PortMapping.Protocol.UDP, " UDP POT Forwarding"); 


     UpnpService upnpService = new UpnpServiceImpl(); 
     RegistryListener registryListener = new PortMappingListener(desiredMapping); 
     upnpService.getRegistry().addListener(registryListener); 

     upnpService.getControlPoint().search(); 

    } 
4

Clingには、このようなportforwadポートが必要なときにいくつかの問題があります。 あなたはこのコードを使用する必要があります。

UpnpServiceImpl upnpService = null; 
PortMapping[] arr = new PortMapping[2]; 

    arr[0] = new PortMapping(7777, InetAddress.getLocalHost().getHostAddress(), PortMapping.Protocol.TCP,"My Port Mapping1");  
    arr[1] = new PortMapping(7777, InetAddress.getLocalHost().getHostAddress(), PortMapping.Protocol.UDP,"My Port Mapping2"); 

    upnpService = new UpnpServiceImpl(new PortMappingListener(arr));    

    upnpService.getControlPoint().search();   

は、ルータ上のUPnPをオンにすることを忘れないでください。

そして、あなたの通信が終了したとき、あなたはこのようにそれをオフにする必要があります:あなたは、コードの下に使用してあなたの目標を達成することができ

upnpService.shutdown(); 
関連する問題