Sunday, October 25, 2009

Port 80 may not be a clean path

If you want to host a socket based application on internet, port 80 may not be a clean path to be picked.

A socket based application could be used when application creates a socket and communicates using custom data format like xml and delimited texts.A chat application is a example of socket application. There is a need for continous open connection which will flow chat text to client from server.

Generally client application which wants to do socket communication can rely on technique of http tunneling where a get request is made to a web server and once the socket is opened custom data fromats could be exchanged.

The problem faced here is which port should be selected for hosting chat server.
Selecting port 80 will work in 95 percent of cases and 5 percent of users might face any of problems mentioned ahead.

Request/Reponse: An ISP may route all the requests received from port 80 through proxy server. Proxy server works on request response basis, which means once request is received and forwarded to server and server has started responding, no more request can be received from client on same request connection. So the upstream data or the outbound communication on the client system may not work or hang.

Buffer data: An ISP proxy may buffer given number of bytes received from server and then flow the data to client. This may be done for caching at proxy level. It can also be used to detect if the response is any virus file. However, as per my knowledge hardly any ISPs scan for virus data.In this case inbound link may hand till configured bytes are read.

Proxy Load Balance: Some ISPs may route each request received from client on a load balanced proxy servers. This will cause each request to get different IP. To experience this you can visit www.whatismyip.com and check if your IP address is changing on every request. Try it 5/6 times to ensure it. This may affect those services which are using source ip for some kind of processing on server.

Header modification: When the data is routed through proxy servers at ISP, there are chances that the proxy server may add some additional headers on your reponse. If your application is not tolerant then you may have hard time solving this issue.
Some spyware installed on clients system mostly monitor request on port 80 and may tamper with request response headers.

Antivirus,Firewall,Spyware: However these are client end configurations, if may also affect socket communication. The application executables which are making socket communications should be added in antivirus and firewall exceptions.
Spyware are nasty to the extent of discarding application headers and putting their own headers. So avoid sending application data in http response headers. Your http response headers may not reach client system or may be manipulated.

Choosing a non 80 path may save you from above problems. If all your clients are using direct internet connection you may easily use non 80 port. However if you have users sitting in corporate offices surfing internet thorugh corporate proxy server then selecting non 80 path may be difficult.

This blog entry also to some extent explains how ISPs work internally. If you want ensure that your application works with with most ISPs do test you application with atleast 7-8 proxy servers before going on internet.

Monday, September 28, 2009

Development of Rural India

Although india is a fast developing nation, but the benefits of development is not reaching in deeper part of india. Unemployment, lack of basic infrastructure like Roads, Irrigation, Electricity are major problems. if these problems are solved through some structural changes india can become super fast growing economy.

Road construction companies should keep doing surveys about where they can create new roads n where they can do repairs. Instead of government ordering them they should proactively do it. Same applies to Dams construction.. Development should be pull based rather than push based. Somewhere i feel that indian corporate is more trustworthy than the local political representative.

Government has to solve irrigation problem asap as farming is still not a profit making business for major section of farmers. There is huge risk in farming as much is dependent on rains. If government cannot gurantee irrigation then farming should be nationalised in such regions. Afterall government cant leave people to make irrational choices of doing farming n trapping themselves in losses and debts. Many times farmers take double risk of rains and cash crops which often proves fatal.

There are so many industrial estates which are under ot not utilised. Work should be outsourced to from urban areas to such remote locations and railway frieghts should be waived on such outsourcing.

Sunday, August 30, 2009

Swing ResultSet Column Table Component

Hear is a ready to use component for JTable in swing which will also show column titles. By default the JTable only displays the data which is strange although. This code is free and can be used easliy in commercial and opensource applications.
Yet this component does not have alignment facility depending on Integer or String or Date datatypes. Will update once done.

Steps to use the class
1. Create a class ResultSetTableModel.java in package src.components.
2. Create a JTable and add it to JScrollPane.
JTable tblSuppliers = new JTable();
tblSuppliers.setVisible(true);
JScrollPane scrollpane = new JScrollPane(tblSuppliers);
pnlCenter.add(scrollpane,BorderLayout.CENTER);
3. Create the ResultSet,Create Model and set Model.
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(strQuery);
ResultSetTableModel qtm = new ResultSetTableModel();
qtm.setResultSet(rs);
tblSuppliers.setAutoCreateColumnsFromModel(true);
tblSuppliers.setModel(qtm);


Code for ResultSetTableModel.java is as follows.
package src.components;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

public class ResultSetTableModel extends AbstractTableModel {
Vector cache;

int colCount;

String[] headers;

String currentURL;

public ResultSetTableModel() {
cache = new Vector();
}

public String getColumnName(int i) {
return headers[i];
}

public int getColumnCount() {
return colCount;
}

public int getRowCount() {
return cache.size();
}

public Object getValueAt(int row, int col) {
return ((String[]) cache.elementAt(row))[col];
}

public void setResultSet(ResultSet rs) {
cache = new Vector();
try {
ResultSetMetaData meta = rs.getMetaData();
colCount = meta.getColumnCount();

headers = new String[colCount];
for (int h = 1; h <= colCount; h++) {
headers[h - 1] = meta.getColumnName(h);
}

while (rs.next()) {
String[] record = new String[colCount];
for (int i = 0; i < colCount; i++) {
record[i] = rs.getString(i + 1);
}
cache.addElement(record);
}
fireTableChanged(null);
} catch (Exception e) {
cache = new Vector();
e.printStackTrace();
}
}

}

Saturday, August 29, 2009

Browser Embed In Swing

SWT Browser component is quite handy when you want to include support for platform independent browser support from your swing application.
Its more over important when you want to show modal window with a browser, because in case of non modal window you can anyways start IE instance from Runtime call.

The benefit of using Browser component in Swing is that it gives you enough control over the contents you can change anytime from website.
Also its saves you the time of rewriting the stuff written in Website again in Swing or AWT. Same stuff can be used here by directly pointing to Website Form/Page URL.

You have 2 options to go with.
1. chrriis.dj.nativeswing.swtimpl.components.JWebBrowser and
2. org.eclipse.swt.browser.Browser

I would suggest you to go with SWT Browser component.
One problem you will face with JWebBrowser is that the component creates problem with java 1.6. Its makes whole application
go crazy and all screens seams to get repaint problems.
Another problem you will face in JWebBrowser is that the component shows Custom window then a window.open call is made in
HTML page. You might like to open it in Default webbrowser of your operating system.
It allthemore becomes unacceptable when you have shown JWebBrowser component in JDialog window and you have clicked on window.open link.
It will show a window which is kind of hung and you cannot scroll or do any thing with the new window until you close the modal window.
One more problem you will encounter with JWebBrowser is that if you want to decide if opening of new window is to be allowed should be allowed
or not on the basis of URL location clicked, you have to
make a hidden JWebBrowser Component,
set it as browser instead of new window browser.
Dispose the new window using arg0.getNewWebBrowser().getWebBrowserWindow().dispose() in windowWillOpen open.
Ensure that you dispose the new window before setting the webbrowser.
Cancel the Opening of URL in locationChanging event and get the URL.
These long steps are to be followed if you want to intercept the opening up of new Window.

Good thing about JWebBrowser is that it is licensed under LGPL. So you can use it in your commercial projects also. You need not publish your code to users in case of LGPL.
A word for Christopher Deckers, author of JWebBrowser. Please make it work under Java 1.6. Just a call to NativeInterface.open starts the problems of repainting the windows.

However going with SWT Browser is not a eazy path either. You may face problems like
1. JVM Crashes
2. Not fitting easily in JDialog window and fits in JFrame.
3. Browser opens up in JDialog only once and dont come up next time onwards.
4. Your JDialog window shows up but the Browser dont show up.

To avoid JVM Crashes ensure that your window creation and displaying is all in SwingUtilities.invokeLater.
Let the shell loop be out of SwingUtilities.invokeLater. To ensure that JDialog and Browser both shows up,
you set location, size and visible for canvas, shell and browser component.
To ensure that the browser always comes up on window you might have to make use of small sleeps of 1 second outside your SwingUtilities.invokeLater.
This is to ensure that Window is created and shownup on screen before you try to set the browser component on the window.

The code written using SWT Browser component is completely platform independent. You can run vncserver service on your linux box and connect to it using vncclient and see your
application running in Linux environment using MOZILLA browser instead of IE.


If you need any advice or help on the topic please leave a comment here.

Friday, May 15, 2009

JVM Crash in Java Awt Client Exe

The JVM for Java is written in c++ language. When a JVM crashes it creats a file in hard disk from where the class is running. The file contains name of error. For Example EXCEPTION_ACCESS_VIOLATION. So how do you solve this error. The error file may state the thread in which the error occured. Once that is known you can apply some logic regarding what may the reason for crash.

If you are facing error in awt.dll and AWT-Windows" daemon, chances are that you are getting this error because of request focus. Check again the request focus calls. Some of the request focus may not be useful.

Saturday, April 25, 2009

Keep Updated to Google News through RSS

Are you in one of following situations.

1. You are staunch user of RSS Reader and less of Mail
2. You scroll through daily news paper and look only for specific subjects of new.
3. You are student and like to read more online and less from books.
4. You want to get news for all major news paper in your Reader for your topics.
5. Basically, You want Google News Alerts in Reader instead of Your Mail box.

Just now I noticed, RSS feed provided in Google News page. I dont know since when it is available, but i am quite sure its added there of late. I had a long list of subscription of Google News Alert around 2 years back. But ever since i shifted to Google Reader i have disabled all Google News Alerts.

RSS feed on Google News is rightly put there.. exactly as per my expectation and requirement..

Monday, April 20, 2009

Oracle Improves Productline

Oracle is now able to provide range of products and services to its clients like Storage, computers, operating system, database, middle ware and applications. This is because Oracle and Sun's product line compliment each other. However,clouds of uncertainty started hovering above overlapping areas like MySQL, Glassfish and Java. MySql however is not a straight competitor of Oracle database as user base is different.
This deal seems to be more beneficial form Oracle's point of view.It would be interesting to see how Java is able to grow under love and affection of this Step mother. With this deal, all Sun project seams to go on a slow track for some time as Oracle probably will be evaluating each of them and try to align them with their goals. IBM would surely be repenting on missing the deal with Sun.

Java Community favours the deal over IBM because Oracle would do more justice to take it ahead. IBM already have java based products but doesn't seam to be committed to high standards and reliability as is Oracle. Sun was more than generous at funding projects like JavaFx,Openoffice,NetBeans. This would change now I think!!