How to check whether a port is open at client's network/firewall?

前端 未结 8 1420
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 13:13

This is solved at last with \"timeout\" attribute of jQuery AJAX (and JSONP). See my own answer !

Please see the updated part, I

8条回答
  •  独厮守ぢ
    2020-11-30 13:33

    Here is a Java code as an Applet to test server/port connectivity:

    import java.io.*;
    import java.net.*;
    
    public class ConnectionTestApplet extends Applet {
        public void start() {
            boolean portAvailable = false;
            int delay = 1000; // 1 s
            try {
                Socket socket = new Socket();
                socket.connect(new InetSocketAddress("server.domain.com", 1935), delay);
                portAvailable = socket.isConnected();
                socket.close();
            } catch (UnknownHostException uhe) {
                uhe.printStackTrace();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            System.out.println("Connection possible: " + portAvailable);
        }
    }
    

    You still have to get the information out of the applet to do something else with that result. The easiest way is to redirect the browser thanks to getAppletContext().showDocument(url)

提交回复
热议问题