Skip to main content

Posts

Showing posts from May, 2010

"(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.