J2ME - UDP/Datagram - Siemens TC45 cellular engine

Discussion in 'Java' started by Jonas Hei, Jun 14, 2004.

  1. Jonas Hei

    Jonas Hei Guest

    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) {
    }
    }
    Jonas Hei, Jun 14, 2004
    #1
    1. Advertising

  2. Jonas Hei wrote:

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

    <snip>
    > 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 <>
    * @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
    */
    Darryl L. Pierce, Jun 14, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Javayang
    Replies:
    1
    Views:
    1,110
    Steve Horsley
    Sep 11, 2003
  2. Replies:
    2
    Views:
    2,977
    David Van de Voorde
    Jan 21, 2005
  3. -
    Replies:
    11
    Views:
    1,650
    Gordon Beaton
    Aug 26, 2005
  4. matt
    Replies:
    0
    Views:
    522
  5. RayKnight

    Siemens MC35i Cellular Engine

    RayKnight, Apr 28, 2005, in forum: C Programming
    Replies:
    4
    Views:
    482
    Keith Thompson
    May 3, 2005
Loading...

Share This Page