import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

class Reproducer
{
    public static void main(String[] args) throws InterruptedException
    {
        System.setProperty("java.net.useSystemProxies", "true");
        final int port = 54434;
        Thread server = serverThread(port);
        Thread client = clientThread(port);
        server.start();
        client.start();
        server.join();
        client.join();
    }

    private static Thread serverThread(int port)
    {
        return new Thread(() -> {
            try (ServerSocket serverSocket = new ServerSocket())
            {
                serverSocket.bind(new InetSocketAddress(port));
                serverSocket.accept();
                System.out.println("Got connection from socket, exit.");
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
        });
    }

    private static Thread clientThread(int port) {
        return new Thread(() -> {
            try (Socket socket = new Socket())
            {
                //using "localhost" here will work
                socket.connect(new InetSocketAddress("127.0.0.1", port), 2500);
            }
            catch (IOException e)
            {
                //should be able to connect, but will fail with connection refused due to proxy
                e.printStackTrace();
                System.exit(1);
            }
        });
    }
} 