Configuring maximum number of simultaneous open WebSockets (for IE)

Given I’ve got this JS application. All client side JS communicating using web sockets. One page may have multiple web sockets open as many as 10-15.

Firefox and Chrome handle this many open web sockets at once just fine. IE11 seemed to have a limitation of 6 open web sockets at once.

Once I open that 7th web socket, regardless of socket call to the third-party server, I got an error thrown by IE, which closes the socket and gives the general error “SecurityError” and expanding the __proto__ section it gives me . The error seems to be pretty generic.

At first it looks as if there may be a trusted zone type issue with IE, but even after adding the client site to trusted zone as well as the server providing the data, the error still persisted.

Solution

This site shows the max connections settings for IE. It’s a registry setting in Windows that controls the amount of web socket connections.

Interestingly enough, By default, windows doesn’t have that registry key, but there is still a limit. Therefore you have to add the Registry in order for this to work.

The MSDN Section mentions:


WebSocket Maximum Server Connections

Internet Explorer 10. When enabled, the FEATURE_WEBSOCKET_MAXCONNECTIONSPERSERVER feature sets the maximum number of concurrent WebSocket connections allowed to a single host. The minimum number that can be specified is 2 and the maximum value allowed is 128.

The default value for this setting is 6 in Internet Explorer and applications hosting the WebBrowser Control. To modify this feature by using the registry, add the name of your executable file to the following setting.

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
   SOFTWARE
      Microsoft
         Internet Explorer
            Main
               FeatureControl
                  FEATURE_WEBSOCKET_MAXCONNECTIONSPERSERVER
                     contoso.exe = (DWORD) 0x00000006 (6)

This should fix the problem.

Source

MSDN

How to make ajax call in spring framework

Write a server side method, with a mapping something as follows:

@RequestMapping("/getKids.html")   
public @ResponseBody
String getChildren(@RequestParam(value = "ocn") String ocn,
HttpServletRequest request, HttpServletResponse response)
{
return ocn.toUpperCase();
}

Here @ResponseBody tells the framework to return value of the method to the browser and not lookup for a view with that name.
You can optionally omit request and response parameters in the signature of the method, if you like to.

After removal of request and response the method will look like

@RequestMapping("/getKids.html")   
public @ResponseBody
String getChildren(@RequestParam(value = "ocn") String ocn)
{
return ocn.toUpperCase();
}

Write a javascript method as follows (This uses jquery to fire ajax request)

function populateSubAgents(obj)
{
$.ajax({
url: "getKids.html?ocn="+obj.value,
success: function(data) {
$("#subAgentName").html(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (XMLHttpRequest.status == 0) {
alert(' Check Your Network.');
} else if (XMLHttpRequest.status == 404) {
alert('Requested URL not found.');
} else if (XMLHttpRequest.status == 500) {
alert('Internel Server Error.');
} else {
alert('Unknown Error.n' + XMLHttpRequest.responseText);
}
}
});
}

How to download a file using AJAX

I struggled for half of my day finding this.

Actually in our project, there is a CART. The requirement is when we click on downloadCart button, it should download the contents of the cart and clear the cart as well.

The first issue that I faced was…

As the response has a zip file to be downloaded, hence in our Action class, they were writing bytes to the response, and in the end, when they return SUCCESS, (I forgot to tell u, we are using struts in our project) it gives an exception : java.lang.illegalStateException, that is expected.

So, what’s the solution…

After discussing this with my friend Sukhbir, he suggested that we can’t return any view after we have committed the response. But how to handle this scenario.

He suggested, make 2 calls, using javascript, and put it on onClick event of the button.
One for downloading, and the second one for re-loading the cart (So that it gets refreshed).

I did the code for downloading using AJAX…. $.get and $.ajax
But the issue now came up was….

Ajax calls work in background and it doesn’t lets the user see that something has downloaded……no response, no prompt…….nothing……..

Now what??

Then I came to know that there are APIs available in jquery for handling binary data when data is coming from server. I googled this also a lot, but, couldn’t find anything that worked for me.

I found a very pretty and simple solution on internet now…Here it is…
Thanks to Eric for this help

Source : Google Group Forums Link

Final Solution

function test(url){ 
var elemIF = document.createElement("iframe");
elemIF.src = url;
elemIF.style.display = "none";
document.body.appendChild(elemIF);
}

Related posts : http://particletree.com/notebook/ajax-file-download-or-not/

JSON, AJAX and jQuery

Today I was working on JSON.
1) Requirement was to get the data from a server in a JSON object. Store it into request object.
2) And on an HTML page, it was required to fire an AJAX request, get the data from the Servlet created in step 1.

3) When i fired a request to servlet directly in browser window, it used to print JSON object that it returns. But when i make a request thru AJAX call… the data is never displayed.

SOLUTION/MISTAKE:

JSON object must follow the structure of the JSON object.
You cannot add any extra println in the resulting JSP. It must ONLY and ONLY print JSON object.

You can validate your JSON from www.jsonlint.com

See more : http://api.jquery.com/jQuery.ajax/