Discussion Board

Results 1 to 3 of 3

Thread: need help

  1. #1
    Registered User souhir's Avatar
    Join Date
    Feb 2010
    Posts
    32
    dear sir
    i have this part of a code that a mobile send input coordinate (startx and starty) to a server using socket
    how can i modify it so that the line in main class
    System.out.println("startx1"+startx);

    will display the sended value
    and how to modify the socket code in order to send image from server to mobile
    with best regard



    public class test extends Component {

    public static void main(String args[]) {
    connect();
    System.out.println("startx1"+startx);
    }

    public static void connect() {
    try {
    System.out.println("S: Connecting...");
    ServerSocket serverSocket = new ServerSocket(12344);
    toClient = serverSocket.accept();
    System.out.println("S: Connected");
    Thread desktopServerThread = new Thread(){
    public void run(){
    while(true){
    try {
    in= new BufferedReader(new InputStreamReader(toClient.getInputStream()));
    String str;
    if (!(str=in.readLine()).equals("") | !str.equals(" "))
    System.out.println("C: '" + str);
    int b = str.indexOf('d');
    String startpt = str.substring(1, b);
    int bbb=startpt.indexOf(',');
    String bx = startpt.substring(0, bbb);
    String by = startpt.substring(bbb+1);
    startx=Float.valueOf(bx.trim()).intValue();
    starty=Float.valueOf(by.trim()).intValue();
    String destpt = str.substring(b+1);
    System.out.println("Sending Message Succesful"+" s "+startpt+" d "+destpt);
    System.out.println("xx "+startx+" yy "+starty);
    } catch(Exception e) {
    System.out.println("S: Error");
    e.printStackTrace();
    break;
    }
    }
    }
    };
    desktopServerThread.start();
    } catch (Exception e) {
    System.out.println("S: Connection Error");
    e.printStackTrace();
    }
    }
    }

  2. #2
    Nokia Developer Champion raj_J2ME's Avatar
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,314
    I wonder if you are writing the Java ME code.So I am not sure that what are you actually trying to do??

    You can check if this helps you, please create the instance of the class that you have declared inside the main() and then you can call that connect() method inside the constructor of the class.

    This is basic thing in core java.Please read the basics in much more details.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Nokia Developer Champion Tiger79's Avatar
    Join Date
    Apr 2007
    Posts
    2,697
    actually I don't see a startApp method or anything like that except from the main method, which is typical for "normal" java but not for J2ME...
    So I am guessing this is no MIDlet at all...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved