J2ME - UDP/Datagram - Siemens TC45 cellular engine

J

Jonas Hei

Hi,

I need to build an application for the siemens tc45 cellular engine.
It supports j2me. I have not been able to find any example code for doing
UDP (datagram) commuication using the J2ME (MIDP or siemens implementation
of MIDP [called as IMP]).
I have pasted the code below - it however doesn't seem to work. I have not
tried executing it in the tc45 yet, but when I execute it in the emulator
it hangs (doesn't return) on the method dgc.send(dg).

Any ideas, tips in general or specifically related to datagram client
implementation will be greatly appreciated.
Thanks.

The code:
import javax.microedition.midlet.*;
import java.io.*;
import javax.microedition.io.*;
import java.util.*;
import com.siemens.icm.io.*;

public class One extends MIDlet {
public One() {
}
public void init() throws MIDletStateChangeException {
}
public void startApp() throws MIDletStateChangeException {
doWork();
sendMessage();
notifyDestroyed();
}
public void sendMessage() {
try {
DatagramConnection dgc = null;
dgc = (DatagramConnection)
Connector.open("datagram://192.32.80.192:9001");
String datastring = "such and such work done";
byte[] buf = datastring.getBytes();
Datagram dg = dgc.newDatagram(buf,datastring.length());
//dg.setAddress("datagram://192.32.80.192:9001");
dgc.send(dg);
dgc.close();
}
catch(IllegalArgumentException e3) {
System.out.println(e3);
}
catch(InterruptedIOException e1) {
System.out.println(e1);
}
catch(IOException e) {
System.out.println(e);
}
}
public void pauseApp() {
}
public void destroyApp(boolean cond) {
}
}
 
D

Darryl L. Pierce

Jonas said:
Hi,

I need to build an application for the siemens tc45 cellular engine.
It supports j2me. I have not been able to find any example code for doing
UDP (datagram) commuication using the J2ME (MIDP or siemens implementation
of MIDP [called as IMP]).
I have pasted the code below - it however doesn't seem to work. I have not
tried executing it in the tc45 yet, but when I execute it in the emulator
it hangs (doesn't return) on the method dgc.send(dg).

Have you verified that the device *supports* datagrams? I can't find a
reference to the TC45 on Siemens's website.
Any ideas, tips in general or specifically related to datagram client
implementation will be greatly appreciated.
public void startApp() throws MIDletStateChangeException {

First off, move the networking code *out* of the startApp() method. It's
*very bad mojo* to do such functions in the lifecycle methods. Those
methods are meant to return as quickly as possible. Your code is blocking
the main thread which is quite bad. Instead, you should throw up a
Displayable object and attach a Command to it. When that Command is
selected you should then spawn a *separate thread* and have that thread
handle the networking traffic.

--
/**
* @author Darryl L. Pierce <[email protected]>
* @see The J2ME FAQ <http://mypage.org/mcpierce/j2mefaq.html>
* @quote "What do you care what others think, Mr. Feynman?"
* @geek echo '$_ = "Jvtu bopuifs Pfsm ibdlfs."; y/a-z/za-y/; print' |
perl
*/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top