Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

building a semi-connected application

 
Henk Rog
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody know a way to do something like this in J2ME:
Building a semi-connected application
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henk Rog
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Smart Ticket blueprint might be a good start.
 
Henk Rog
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic