This is finally solved with the jQuery AJAX (and JSONP) timeout attribute. See my own answer!
Please view the updated part, I also tried the applet. And feel free to accept your answer if you can give a solution with an applet implementation.
I am working with a Java based web application. My requirement is to check if a specific port (for example, 1935) is open or blocked on the client side. I implemented "jsonp" (why "jsonp"? I found that the http request through AJAX cannot work for corssdomain for the same browser origin policy). AJAX call to one of my servers containing a specific port. And if the server returns xhr.status == 200
, the port is open. Here is a drawback that I cannot make wait for execution (synchronously) until the call ends. Here is the JavaScript function I'm using.
Any alternative solution (should be on the client side should be in parallel with my application, please do not offer python / php / other languages). Thank you 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 tried using a Java applet (thanks to a suggestion by Y Martin). This works great in appletviewer. But when I add the applet to the HTML page, it gives vulnerable results. Vulnerable in the sense that when I change the tab or resize the browser, the portAvailable
value changes 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;
And this is my HTML page (I host it on the same computer as another Tomcat 6, which runs on port 9090. I can view this page from url ---> http://101.220.25.76:9090/test/
):
<html> <body> <applet code="ConnectionTestApplet" width=300 height=50> </applet> </body> </html>
And how do I lock and open port 1935?
I created a firewall rule for inbound and outbound for port 1935. I am checking the script for opening / blocking port 1935 by disabling / enabling both rules.
This is my SSCCE . Now please help me :)