Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:01:07+00:00 2026-06-01T12:01:07+00:00

This is solved at last with timeout attribute of jQuery AJAX (and JSONP). See

  • 0

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

Please see the updated part, I have tried with applet too. And will not hesitate to accept your answer if you can give a solution with applet implementation.

I am working with a Java based web application. My requirement is to check whether a particular port (say 1935) is open or blocked at client’s end. I have implemented a “jsonp” (why ‘jsonp’ ? i found that ‘http’ request through AJAX cannot work for corssdomain for browsers ‘same origin policy’) AJAX call to one of my server containing particular port. And if the server returns xhr.status == 200 the port is open. Here is a drawback that I can’t make the execution-flow wait (synchronous) until the call completes. Here is the JavaScript function I am using.

Any alternative solution (must be a client-sided thing must be parallel with my application, please dont suggest python/php/other languages) is also welcome. Thanks for your time.

function checkURL() {

    var url = "http://10.0.5.255:1935/contextname" ;
    var isAccessible = false;

    $.ajax({
        url: url,
        type: "get",
        cache: false,
        dataType: 'jsonp',
        crossDomain : true,
        asynchronous : false,
        jsonpCallback: 'deadCode',
        complete : function(xhr, responseText, thrownError) {
            if(xhr.status == "200") {
                isAccessible = true;
                alert("Request complete, isAccessible==> " + isAccessible); // this alert does not come when port is blocked
            }
        }
    });

    alert("returning isAccessible=> "+ isAccessible); //this alert comes 2 times before and after the AJAX call when port is open
    return isAccessible;

}

function deadCode() {
    alert("Inside Deadcode"); // this does not execute in any cases
}

———————————————————UPDATE—————————————————————-

I have tried with Java Applet (thanks to Y Martin’s suggestion). This is working fine in appletviewer. But when I add the applet in HTML page, it is giving vulnerable results. Vulnerable in the sense, when I change the tab or resize the browser, the value of portAvailable is being altered in the printed message.

Applet Code :

import java.applet.Applet;
import java.awt.Graphics;
import java.net.InetSocketAddress;
import java.net.Socket;

public class ConnectionTestApplet extends Applet {
    private static boolean portAvailable;
    public void start() {
        int delay = 1000; // 1 s
        try {
            Socket socket = new Socket();
                /*****This is my tomcat5.5 which running on port 1935*************/
                /***I can view it with url--> http://101.220.25.76:1935/**********/
            socket.connect(new InetSocketAddress("101.220.25.76", 1935), delay);
            portAvailable = socket.isConnected();
            socket.close();
            System.out.println("init() giving--->  " + portAvailable);
        }
        catch (Exception e) {
            portAvailable = false;
            System.out.println("init() giving--->  " + portAvailable);
            System.out.println("Threw error---> " + e.getMessage());
        }

    }
    public void paint(Graphics g) {
        System.out.println("Connection possible---> " + portAvailable);
        String msg = "Connection possible---> " + portAvailable;
        g.drawString(msg, 10, 30);
    }
}

And this is my HTML page (I am hosting it on same computer with a different Tomcat 6 which runs on port 9090. I can view this page with url —> http://101.220.25.76:9090/test/):

<html>
<body>
        <applet code="ConnectionTestApplet" width=300 height=50>
        </applet>
</body>
</html>

And how I am doing the port 1935 blocking and openning ?

I have created firewall rule for both inbound and outbound for port 1935.
I check the port 1935 open/blocked scenario by disabling/enabling both rules.

This is my S.S.C.C.E. Now please help me 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:01:08+00:00Added an answer on June 1, 2026 at 12:01 pm

    Gotcha !!! I have solved my problem with JSONP and jQuery AJAX call. I discovered the timeout attribute of jQuery AJAX and my code executed fluently when the port was blocked or opened. Here is the solution for future visitors. Thanks to all answerers for contribution.

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
            <script type="text/javascript" src="jquery-1.7.2-min.js"></script>
        </head>
        <body>
            <script type"text/javascript">
                var isAccessible = null;
                function checkConnection() {
                    var url = "http://101.212.33.60:1935/test/hello.html" ;
                    $.ajax({
                        url: url,
                        type: "get",
                        cache: false,
                        dataType: 'jsonp', // it is for supporting crossdomain
                        crossDomain : true,
                        asynchronous : false,
                        jsonpCallback: 'deadCode',
                        timeout : 1500, // set a timeout in milliseconds
                        complete : function(xhr, responseText, thrownError) {
                            if(xhr.status == "200") {
                               isAccessible = true;
                               success(); // yes response came, esecute success()
                            }
                            else {
                               isAccessible = false;
                               failure(); // this will be executed after the request gets timed out due to blockage of ports/connections/IPs
                            }
                        }
                   });
                }
                $(document).ready( function() {
                    checkConnection(); // here I invoke the checking function
                });
            </script>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: I have solved this by myself. See my answer below I have set
I have solved this problem, I just need to know what to do. I
This is an Amazon interview Question.I have solved this problem in O(n) using dynamic
I bet somebody has solved this before, but my searches have come up empty.
has anyone solved this? Whenever I have submit button, I have to go in
last.fm has this nifty feature when you're adding an event. you have the Artists
I'm asking this question because I finally solved a problem that I have been
The last few days we see this error message in our website too much:
ok guys, u solved this so fast last time. i've altered my sub lists
This is solved, but I can't mark it as such for 2 days. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.