2013-03-10 3 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

이와 같이 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();