Testing ports

I’m hosting my webapp on a server and setup apache to for a proxy to the webapp. This does work, but a direct connection would be faster and less fragile. Now i am looking for a method to test if the client can connect directly to the port. If the client can connect directly to the port i want to forward him using showurl, otherwise continue using the proxy.

I can detect is the user is using the proxy, but i have no method of testing if the client can connect directly to the port.