Código de exemplo Java-Client PHP-Server UDP Hole Punching

Estou trabalhando em um projeto que exigirá um servidor p2p, mas não encontrei nenhum código de exemplo java-client php-server. Entendo o conceito de como funciona a perfuração udp, mas não consigo fazer nada funcionar em código.

O que eu tentei:

TheSocket.java

public class TheSocket {

public static String response = "hello";
public static String request;
public static String webServerAddress;

public static ServerSocket s;

protected static ServerSocket getServerSocket(int port)throws Exception{
    return new ServerSocket(port);
}

public static void handleRequest(Socket s){
    BufferedReader is;
    PrintWriter os;

    try{
        webServerAddress = s.getInetAddress().toString();
        is = new BufferedReader(new InputStreamReader(s.getInputStream()));

        request = is.readLine();

        System.out.println(request);

        os = new PrintWriter(s.getOutputStream(), true);
        os.println("HTTP/1.0 200");
        os.println("Content-type: text/html");
        os.println("Server-name: TheSocket");
        os.println("Content-length: " + response.length());
        os.println("");
        os.println(response);
        os.flush();
        os.close();
        s.close();

    }catch(Exception e){
        System.out.println("Failed to send response to client: " + e.getMessage());
    }finally{
        if(s != null){
            try{
                s.close();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }
    return;
}
}

Main.java

public class Main {

public static void main(String[] args)throws Exception{
    TheSocket.s = TheSocket.getServerSocket(6789);
    while(true){
        Socket serverSocket = TheSocket.s.accept();
        TheSocket.handleRequest(serverSocket);
    }
}

PHP-CONNECT.php - para obter a porta de outros usuários, conecto e uso manualmente a porta mostrada na página da web.

<?php
    echo $_SERVER['REMOTE_ADDR'].':'.$_SERVER['REMOTE_PORT'];
?>

O problema com o código acima é que ele não pode chegar ao soquete, a menos que eu seja portado para a frente.

Comente se você tiver alguma dúvida!

questionAnswers(1)

yourAnswerToTheQuestion