Udp + nokia 3530

É POSSIVEL QUE ALGUEM TENHA FEITO COMUNICAÇÃO UDP COM NOKIA 3530 COM GPRS. ALGUEM PODE AJUDAR.

OBRIGADO

JULIANO

da uma testada ai

 import javax.microedition.lcdui.*;
 import javax.microedition.midlet.*;
 import javax.microedition.io.*;
 import java.util.*;
 
public class UDPTest extends MIDlet implements CommandListener {

    static final String hostname = "203.123.12.201";
    static final int serverport = 9000;
    private Form mainScreen = null;
    static final int sendport = 9000;
    static final int receiveport = 9001;
    private Form resultScreen = null;
    static boolean isOver = false;
    TextField message=null; 

    private Command okCommand = new Command("OK", Command.OK, 1);
    private Command backCommand = new Command("Voltar", Command.BACK, 2);
    private Command exitCommand = new Command("Sair", Command.EXIT, 2);

    private Display myDisplay;

    public UDPTest() {   
        myDisplay = Display.getDisplay(this);
        resultScreen = new Form("Result");
        resultScreen.addCommand(okCommand);
        resultScreen.setCommandListener(this);
        mainScreen = new Form("UDP Testing");
        message=new TextField("Message:"," ",90,TextField.ANY);
        //  mainScreen = new List("UDP Test", List.IMPLICIT);	
    }     

    public void startApp()
        throws MIDletStateChangeException {
        mainScreen.append(message);
        mainScreen.addCommand(okCommand);
        mainScreen.addCommand(exitCommand);
        mainScreen.setCommandListener(this);
        myDisplay.setCurrent(mainScreen);

    }

    public void pauseApp() { }

    public void destroyApp(boolean unconditional) { }

    public void commandAction(Command c, Displayable d) {
        String res = null;
        if ((c == okCommand) && (d == mainScreen)) {
          // int selected = mainScreen.getSelectedIndex();
          try {
            //switch (selected) {
            // case 0:  
               res = sendRequest(message.getString());
               resultScreen.append (res);
               myDisplay.setCurrent(resultScreen);       
               // break;
             // }
            }
            catch (Exception e) {
                System.err.println(e);
            }
        }
        if ((c == exitCommand) && (d == mainScreen)) {
            notifyDestroyed();
        }
        if ((c == okCommand) && (d == resultScreen)) {
            myDisplay.setCurrent(mainScreen);
        }  
    }

    String sendRequest(String request) {
        DatagramListener dgl = new DatagramListener("datagrama://:" + receiveport);
        dgl.start();
        doSend("datagrama://" + hostname + ":" + serverport, request);
        int counter = 0;
        outloop:while (!isOver) {
           if (counter++ &gt 5) break outloop;
           try {
             Thread.sleep(1000);
           } 
           catch (Exception e) {
             System.out.println("Acorda Neo!");
           }
         }

         isOver = false;
         return dgl.data;
         return "Sent";
    }
  
    void doSend(String destAddr, String msg) {
        int length = msg.length();
        byte[] message = new byte[length];
        DatagramConnection dc = null;
        
        System.arraycopy(msg.getBytes(), 0, message, 0, length);
        String localhost = "datagrama://localhost:" + sendport;

        try {
            dc = (DatagramConnection)Connector.open(localhost);
            Datagram dobject = dc.newDatagram(message, length, destAddr);         
            dc.send(dobject);
        } 
        catch (Exception e) {
            System.out.println("Failed to send message: " + e);
        }
        finally {
            if (dc != null) {
                try {
                    dc.close();
                } catch (Exception f) {
                    System.out.println("Flha ao fechar conector: " + f);   
                }
            }
        }
    }
    
    class DatagramListener extends Thread {
        DatagramConnection dc = null;
        Datagram dobject;
        String data = "error";

        DatagramListener(String recvAddr) {
           try {  
               dc = (DatagramConnection)Connector.open(recvAddr);
               dobject = dc.newDatagram(dc.getMaximumLength());
           }
           catch (Exception e) {
               System.out.println("Falha ao finalizar o conector: " + e);
           }
        }

        public void run() {
           try {
              dc.receive(dobject);
              data = new String(dobject.getData(), 0, dobject.getLength());
              isOver = true; 
           } 
           catch (Exception e) {
              System.err.println("Falha ao receber msg:" + e);
           } 
           finally {
              if (dc != null) {
                try {           
                  dc.close();
                } catch (Exception f) {
                  System.err.println("Flaha ao fechar conexão: " + f);   
                }
              }
           }
        }
    }
}

da uma testada ai

 import javax.microedition.lcdui.*;
 import javax.microedition.midlet.*;
 import javax.microedition.io.*;
 import java.util.*;
 
public class UDPTest extends MIDlet implements CommandListener {

    static final String hostname = "203.123.12.201";
    static final int serverport = 9000;
    private Form mainScreen = null;
    static final int sendport = 9000;
    static final int receiveport = 9001;
    private Form resultScreen = null;
    static boolean isOver = false;
    TextField message=null; 

    private Command okCommand = new Command("OK", Command.OK, 1);
    private Command backCommand = new Command("Voltar", Command.BACK, 2);
    private Command exitCommand = new Command("Sair", Command.EXIT, 2);

    private Display myDisplay;

    public UDPTest() {   
        myDisplay = Display.getDisplay(this);
        resultScreen = new Form("Result");
        resultScreen.addCommand(okCommand);
        resultScreen.setCommandListener(this);
        mainScreen = new Form("UDP Testing");
        message=new TextField("Message:"," ",90,TextField.ANY);
        //  mainScreen = new List("UDP Test", List.IMPLICIT);	
    }     

    public void startApp()
        throws MIDletStateChangeException {
        mainScreen.append(message);
        mainScreen.addCommand(okCommand);
        mainScreen.addCommand(exitCommand);
        mainScreen.setCommandListener(this);
        myDisplay.setCurrent(mainScreen);

    }

    public void pauseApp() { }

    public void destroyApp(boolean unconditional) { }

    public void commandAction(Command c, Displayable d) {
        String res = null;
        if ((c == okCommand) && (d == mainScreen)) {
          // int selected = mainScreen.getSelectedIndex();
          try {
            //switch (selected) {
            // case 0:  
               res = sendRequest(message.getString());
               resultScreen.append (res);
               myDisplay.setCurrent(resultScreen);       
               // break;
             // }
            }
            catch (Exception e) {
                System.err.println(e);
            }
        }
        if ((c == exitCommand) && (d == mainScreen)) {
            notifyDestroyed();
        }
        if ((c == okCommand) && (d == resultScreen)) {
            myDisplay.setCurrent(mainScreen);
        }  
    }

    String sendRequest(String request) {
        DatagramListener dgl = new DatagramListener("datagrama://:" + receiveport);
        dgl.start();
        doSend("datagrama://" + hostname + ":" + serverport, request);
        int counter = 0;
        outloop:while (!isOver) {
           if (counter++ &gt 5) break outloop;
           try {
             Thread.sleep(1000);
           } 
           catch (Exception e) {
             System.out.println("Acorda Neo!");
           }
         }

         isOver = false;
         return dgl.data;
         return "Sent";
    }
  
    void doSend(String destAddr, String msg) {
        int length = msg.length();
        byte[] message = new byte[length];
        DatagramConnection dc = null;
        
        System.arraycopy(msg.getBytes(), 0, message, 0, length);
        String localhost = "datagrama://localhost:" + sendport;

        try {
            dc = (DatagramConnection)Connector.open(localhost);
            Datagram dobject = dc.newDatagram(message, length, destAddr);         
            dc.send(dobject);
        } 
        catch (Exception e) {
            System.out.println("Failed to send message: " + e);
        }
        finally {
            if (dc != null) {
                try {
                    dc.close();
                } catch (Exception f) {
                    System.out.println("Flha ao fechar conector: " + f);   
                }
            }
        }
    }
    
    class DatagramListener extends Thread {
        DatagramConnection dc = null;
        Datagram dobject;
        String data = "error";

        DatagramListener(String recvAddr) {
           try {  
               dc = (DatagramConnection)Connector.open(recvAddr);
               dobject = dc.newDatagram(dc.getMaximumLength());
           }
           catch (Exception e) {
               System.out.println("Falha ao finalizar o conector: " + e);
           }
        }

        public void run() {
           try {
              dc.receive(dobject);
              data = new String(dobject.getData(), 0, dobject.getLength());
              isOver = true; 
           } 
           catch (Exception e) {
              System.err.println("Falha ao receber msg:" + e);
           } 
           finally {
              if (dc != null) {
                try {           
                  dc.close();
                } catch (Exception f) {
                  System.err.println("Flaha ao fechar conexão: " + f);   
                }
              }
           }
        }
    }
}