File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes building a semi-connected application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "building a semi-connected application" Watch "building a semi-connected application" New topic
Author

building a semi-connected application

Henk Rog
Ranch Hand

Joined: Dec 04, 2003
Posts: 36
Does anybody know a way to do something like this in J2ME:
Building a semi-connected application
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
The whole point of J2ME is "occassionally connected" apps. Yes, that sort of auto-detecting network and switching between offline/online mode tasks are very easy in J2ME. To detect the network in J2ME, you just send a packet to a server, if it throws an exception, switch to the offline mode in your exception handling code.


Seam Framework: http://www.amazon.com/exec/obidos/ASIN/0137129394/mobileenterpr-20/
Ringful: http://www.ringful.com/
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You should also take a look at the book Michael's sig is boasting. It provides a valuable resource of approaches to implementing such applications.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Henk Rog
Ranch Hand

Joined: Dec 04, 2003
Posts: 36
I think I will take a look at that book.
Are there any examples of that kind of applications on the internet?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The Smart Ticket blueprint might be a good start.
Henk Rog
Ranch Hand

Joined: Dec 04, 2003
Posts: 36
I think I understand how to switch from online mode to offline mode, but how can I automatically detect if the connection is available again?
(offline --> online)
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
By trying?
For example, every 5 minutes try to first connect and then continue in the offline mode if the connection still fails.
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
Originally posted by Lasse Koskela:
By trying?
For example, every 5 minutes try to first connect and then continue in the offline mode if the connection still fails.

This is exactly what that MSDN app does. It uses a timer thread to ping the server every 10 seconds. You can do exactly the same on J2ME using the Timer and TimerTask classes.
Henk Rog
Ranch Hand

Joined: Dec 04, 2003
Posts: 36
And how can I ping in J2ME? Or can I do something else instead of pinging?
[ December 05, 2003: Message edited by: Henk Rog ]
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
Originally posted by Henk Rog:
And how can I ping in J2ME?

You post a byte of data to the server via HTTP and receive the response. If the MIDlet throws an exception in the process, the ping is failed and the Timer re-pings in several minutes.
If you do not want to ping, you can have the server push the data to you via SMS messages or even SIP. But that is a whole new programming paradigm.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: building a semi-connected application