Skip to main content

Posts

Showing posts from 2010

Secure Http

The site can be hosted using secure version of http also, i.e., HTTPS. It sends the information in encrypted form so it's secure. It uses SSL and sends through port number 443 instead of port 80. requires a license/certificate to be purchased to host the site using secured version, i.e., HTTPS.

Handshake in TCP

3 way Handshake: When TCP establishes the connection. Steps followed: 1) SYN packet is sent by A to B with a random sequence number(for initial seq. no.), say SYN 1000 as a request to establish the connection. 2) B sends ACK 1001 indicating to send the packet 1001 assuring the request to be accepted. 3) A sends ACK 1001 to indicate that it has received the request confirmation. 4 Way Handshake: When there's a connection termination then 4 way handshake is used. For termintation of connection in one direction: 1) FIN packet is sent 2) Other party acknowledges it Similar process is followed for connection to end the other way as it's a full duplex connection.

"(ch=in.read)!=-1" not working

While reading through socket's inputStream, you use most of the time "(ch=in.read)!=-1" This thing sometimes doesn't work. So, alternative solution to it is: Append the end of line character at the end of line from the sender's side. Then, use it as terminating condition for loop. End of line can be identified by: '\u0085', '\n', '\r', "\r\n". In my case, it was not working for any other than '\u0085'.

Editor does not contain a main type

If you get an error "editor doesn't contain a main type" in eclipse, solution is : 1) Make sure eclipse created the project as Java project. 2) Just create a new Java project and copy your class into the src folder by import the eventual dependencies and adding all the jar files to it. This should fix the problem.

Implementing cache in mobile (J2ME)

We can maintain cache/history of our visited entries in our mobile. The method that can be used is "RecordStore" how to do it: 1) Open a recordstore 2) add records to it. Note: They'll be stored into mobile memories, you can't see these records as such in mobile Now, when you want to view these records, open the recordstore again if it's closed. just open each record and perform the function. You can append these records in a list so as to show them as a history maintained. Problem welcome...

Filter packets through jpcap

//Open an interface with openDevice(NetworkInterface intrface, int snaplen, boolean promics, int to_ms) JpcapCaptor captor=JpcapCaptor.openDevice(devices[index], 65535, false, 20); captor.setFilter("tcp && src port 6000", true); It'll filter all the TCP packets with source port number 6000. So, all we need to do is pass the parameters and use logical and, or operators.

How to execute jar file in mobile?

When we run our project, it forms a jar file. To run this file in mobile what we need to do is: just transfer the file to mobile device (by any medium: bluetooth or data cable) and open it. It'll run the application in mobile. Note: The problem can come: Your mobile doesn't recognize that jar or doesn't open that jar file. Sol: It is because of MIDP and CLDC configuration you have chosen while building your file. Now, CLDC 1.1 and MIDP 2.0 is supported by almost all the mobiles. Remember, to make MIDP as 2.0

Cannot see any interface while running jpcap

Q: I cannot obtain the list of network interfaces or cannot capture any packets. Why? It may be because you don't have administrative privileges, which are required to run Jpcap-based applications. On Windows 2000/XP, your account should be in the Administrator group. On Windows Vista, even if your account is in the administrator group, you still need to use "run as administrator" option. To use the option, right-click the application icon, and choose "run as administrator". If your application is command-line based, you need to open Command Prompt by using "run as administrator" option, and run your application within that Command Prompt. On Linux/UNIX, you need to become a super user by using 'su' command , or use 'sudo' command to run Jpcap-based applications.

Eclipse error - build path cannot be found

If you run eclipse and it shows a red cross on your project stating the errors as: -java.lan.enum could not be resolved -build path incomplete then right click on project -> build path -> configure build path -> libraries ->add library add JRE System library Your project will start running.

TCP dump

tcp dump enables us to capture the packets over a network. But there might be a problem when you run this on localhost. Like you are running a socket program, and both server and client residdes in localhost only, then it will not work. The reason for it is: " It's not reaching the Network Card (NIC) actually when it's in localhost." This problem has not been reported anywhere. So, always try this thing on two different machines, may be in a LAN. B'coz the request will never reach the card and will not filter request for a particular port.

socket programming in j2me

Well, I found the code for client side everytime but i am not able to find a code working on the server end. So, I ma posting a working code: import java.io.*; import java.net.*; public class mpp_usr { public static void main ( String args[])throws IOException { Socket sock = null; String str =null; InputStream in; byte b[] = new byte[1024]; try { ServerSocket ss = new ServerSocket(9000); sock = ss.accept(); in = sock.getInputStream(); DataInputStream din = new DataInputStream(in); int len; while((len = din.read(b)) > 0) { String req = new String(b,0,len); System.out.print(req); } } catch(IOException ioe) { System.out.println("error"); } } }

gnome-do

if your gnome do or also called dorkey not working. Go to terminal-> ps -A it will show all the processes. kill the process named gnome-do by "kill -9 pro_number" kill one by one all it's processes, at one instance it'll appear. If it still doesn't come, then call in terminal "gnome-do &" and press ctrl+c and exit. Your gnome-do is back.

jdbc mysql cofiguration for eclipse

There might be problem even after installing everything and doing all the coding of jdbc in ubuntu. So, the solution is : just download a mysql-connector.jar file and make your eclipse to point to it. for this: right click on project->properties->libraries here you should see that mysql connector jar. so, add it by clicking on "add external jar" Now, the project will run sound.

use of connector.open()

The Connector.open method is a factory for connections. You do not use the new operator to instantiate connections. This is a smart mechanism, which keeps the static footprint small when the platform does not include implementations for specific connections. The method throws ConnectionNotFoundException if the desired protocol handler is not available.

store from arraylist into hashtable

import java.util.*; import java.io.*; public class ArraytoHash{ public static void main(String[] args) throws IOException{ String key; String value; ArrayList al1 =new ArrayList(); ArrayList al2 = new ArrayList(); System.out.println("Enter key for the hash table : "); al1 = create(); System.out.println("\n"+"Enter value for the key : "); al2 = create(); Object ia1[] = al1.toArray(); Object ia2[] = al2.toArray(); Hashtable hashTable = new Hashtable (); for(int i = 0; i < al1.size(); i++) { key = (ia1[i]).toString(); value = String.valueOf(ia2[i]); hashTable.put(Integer.parseInt(key), value.toString()); } Map map = new TreeMap (hashTable); System.out.println(map); } public static ArrayList create () { ArrayList al = new ArrayList(); try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("How many elements you wan

pdf to word

To convert pdf to word, we have a solution to install kword it's just of 6.5 MB in terminal, type: sudo apt-get install kword and open the pdf doc and just save it as doc.

beginning eclipse

It's very easy to start working on eclipse. This is the best tutorial i found to guide, how to start: http://www.vogella.de/articles/Eclipse/article.html and to open an existing project. go to new-> java project-> same name as of your existing project ->create from existing ( radio button). point to the location where it's located-> next->finish. if you have an ant file, better to open it with ant file. go for new->other->java ->java project from existing using ant->browse the file and just give the project name and finish. Your project is ready but before that you'll need to install ant in your system and set it's environment variable.

how to run j2me

just download netbeans latest version from : http://netbeans.org/downloads/ netbeans have all the stuffs bundled into it, all the toolkits as well as emulator. No need to install anything after that. How to run a project of J2me in netbeans: This is the best tutorial to know how to run it: http://netbeans.org/kb/docs/javame/quickstart.html

database dump and restoration

To create dump of a database, type the following command: $MYSQLDUMP -u $MyUSER -h $MYHOST -p $MyPASS $db > $FILE RESTORE : run MySql administrator -> Restore -> open file (back up) -> Restore. Fill in the required options. You can also change/assign the username and password from administrator itself. It's a bit difficult to do it in ubuntu. Well, here we go for restoration in ubuntu: 1) open terminal 2) mysql -u username -p 3) create database db_name; 4) change db_name; close this terminal 5) open a new terminal 6) sudo -u username -p database_name < db_file.dmp; and we are done with restoration we can check it by opening a new terminal.

build an xml file

go to ; run -> cmd go to the location where your xml file is stored. then type "ant". before that download ant in your system. So, download it and path needs to be set in environment variables for ant to run.

configuration for JDBC

Go to: administrative tools-> ODBC-> User DSN -> Add to which you want to connect, select an option like MySql ODBC driver. Data Source name: name of db. server: localhost user: root click on test. It'll notify if the connection is established or not.

JDBC

sample code for JDBC: class connect { ResultSet rs; Statement stmt; connect() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:temp",username,password); stmt=con.createStatement(); String query; ResultSet rs = stmt.executeQuery(query); } in query always append "+". e.g.: "insert into debit values ("+mob_no+","+amount+")"

which ports are open

To check which ports are open in your system, we use "netstat". In WINDOWS: go for: c:\windows\system32\netsat -a NETSTAT [-a] [-b] [-e] [-n] [-o] [-p proto] [-r] [-s] [-v] [interval] -a Displays all connections and listening ports. -b Displays the executable involved in creating each connection or listening port. In some cases well-known executables host multiple independent components, and in these cases the sequence of components involved in creating the connection or listening port is displayed. In this case the executable name is in [] at the bottom, on top is the component it called, and so forth until TCP/IP was reached. Note that this option can be time-consuming and will fail unless you have sufficient permissions. -e Displays Ethernet statistics. This may be combined with the -s optio

configurations required to run a project in tomcat

How To Store The Application: -create a folder of your project in webapps. -inside that folder create a folder WEB-INf. -inside WEB-INF create 2 more folders namely, classes and lib. -Make a web.xml in WEB-INf. To run your project, you need to configure the xml file ,i.e., web.xml. where you'll store, say, the servlet name and the url pattern which you'll use to open it in your browser. classes folder will contain the compiled files of your java program (.class). go to browser and type: http://localhost:8080/app-folder/url-pattern give localhost or (IP of the connected system) on running start tomcat manager but it'll ask for username and password. So, configure a file: tomcat->conf->tomcat-users modify/add username and password for manager. Now, start the tomcat from terminal by start.bat and go for the URL in the browser. After the completion just type shutdown.bat in command prompt. Note: while installing this, you need to kill all the processes related to tomcat.

how to run apache tomcat server

first download the setup from : http://tomcat.apache.org/download-55.cgi don't download the .msi, rather download a zip file. Now, extract it wherever you want. now, make a folder of your project and store it in webapps folder in apache. open command prompt->cmd now go to location in apache where bin lies. Tomcat->bin->start.bat your tomcat is started.

J2EE inital configuration

For the set up of J2EE, there are various problems one may face initially. The configurations and system's environment variable setting needs to be done. Windows users don't forget to do : Local: C:\> SET MYVAR=widget Global: Use the System Variables dialog. To reach this dialog, right-click the My Computer icon, select the Properties menu item, and select the Environment tab.Enter the variable name and its value, and click the Set button. So, we need to set up the paths of bin of j2se, bin of j2ee and directory of j2ee where it is installed. You can follow the links: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/GettingStarted2.html http://java.sun.com/j2ee/sdk_1.3/install.html People are welcome to discuss their doubts.

J2ME

The stuff is more likely to be about J2ME. J2ME empowers you develop very cool features for your mobile. All you need is a java enabled mobile. Well, we can discuss all the J2ME related problems here. Those who have heard of it first time or want to start working on it.. Here's the hint for them : Go for Hello World example in j2me. So, here's an example for it: http://www.roseindia.net/j2me/hello-world.shtml I would refer the books who really want to go for some of the cool reading stuff: 1) Beginning J2ME novice to professional, Apress 2) The Complete Reference, James Keogh Though, I am not an expert in it but still we can put up our knowledge and experience to make " a mobile, a world in itself".. :D