×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    8

    Post Problem in multithreading while trying to connect server using SOCKET(J2ME Apps)

    Hi all,
    I am trying to connect server using socket in my child thread and my main thread i am showing some animation. when my application start to connect my application got stuck at that movment and user not able to do anything.
    Can any body please tell me whts the probelm and how i will resolve this.

    Thanks in Advance

    Rijwan

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Problem in multithreading while trying to connect server using SOCKET(J2ME Apps)

    Hi Rijwan,

    How long does this "freeze" approximatively lasts? Also, try posting relevant code portions, so It'll be easier to check for possible errors/issues.

    Pit

  3. #3
    Regular Contributor
    Join Date
    Apr 2007
    Posts
    220

    Re: Problem in multithreading while trying to connect server using SOCKET(J2ME Apps)

    HI Rijwan!

    after opening the socket connection have u done any read() call on the inputstream? beacuse the read() is a blocking call!

    One more reason may be the thread structure that you have created...without seeing the code, it may not be possible to guess.

    Regards

    Amit

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    8

    Re: Problem in multithreading while trying to connect server using SOCKET(J2ME Apps)

    Hi Pit,
    Thanks for your response.
    My application got hang......u cant do any thing .....i have forcibli exit from apps.Main thread start when we start application and it comes in enter user id and pass word screen .when i submiting these data to connect server "please wait screen comes with some animation" which is in main thread .In the same time i create another thead for connection ...

    String connectorURL ="socket://"+Constants.TEST_SERVER_IP+":"+Constants.PORT;
    cnnection = (StreamConnection) Connector.open( connectorURL );

    this code run form another threads.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    8

    Re: Problem in multithreading while trying to connect server using SOCKET(J2ME Apps)

    Hi Amit,
    Yes i did but with different threads.As its JME apps so the structer is simple for animtion and drawing i used main thread and wherever i required to get/set data from server i used another thread.

    Thanks
    Rijwan

  6. #6
    Registered User
    Join Date
    Mar 2005
    Posts
    8

    Re: Problem in multithreading while trying to connect server using SOCKET(J2ME Apps)

    Sorry to all of you one thing i missed to mensioned is I am trying to connect wrong server meanse there is some exception and i handled this excepiton .my actual problem is that while i am using different thread for this purpose..so why my main thread get stuck and my apps got hang..

    Thanks
    RIjwan

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    8

    Re: Problem in multithreading while trying to connect server using SOCKET(J2ME Apps)

    Hi All
    Let me explaint the problem in detailed.

    In J2ME apps i am using 2 thread.

    1. for my animation
    2. for connection


    If it finds a correct destination then its fine.
    If i give wrong destination then it blocks(around 15 to 20 second) the main thread while trying to connect

    I want my main thread to run while the child thread is trying to connect.

    Can any one help me out find the code example below.
    this the code sample

    *****************************************************************************
    import javax.microedition.lcdui.game.GameCanvas;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import java.io.*;
    class HelloCanvas extends GameCanvas implements Runnable {

    int mainWidth;
    int mainHeight;
    int keyValue;
    CanvasSize mid;
    Thread temp ;
    NetConnection nc;
    static String status="Not connected";
    int ctr;
    public HelloCanvas(CanvasSize mid){

    super(true);
    this.mid = mid;
    temp = new Thread(this);
    setFullScreenMode(true);
    nc= new NetConnection();
    temp.start();
    }

    public void run(){

    try{
    while(true){
    repaint();
    temp.sleep(80);
    }
    }catch(Exception e){}
    }
    public void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();
    g.setColor(0xffffff);
    g.fillRect(0, 0, width, height);
    g.setColor(0,0,0);
    String dot="";
    for(int i=0;i<ctr;i++)
    dot=dot+".";
    g.drawString(status+dot+" "+keyValue,20,100,0);
    ctr++;
    if(ctr>=3)
    ctr=0;

    }
    public void showNotify(){
    mainWidth =getWidth();
    mainHeight =getHeight();

    }

    public void keyPressed(int keyCode){
    System.out.println("-->"+keyCode);
    keyValue = keyCode;
    status="trying to coennct";
    nc.connect();


    }


    }


    class NetConnection implements Runnable{
    Thread t;
    //StreamReader m_reader;
    //StreamWriter m_writer;

    StreamConnection connection;
    public NetConnection(){

    }
    public void notifyConnect() throws IOException{
    //m_reader=new StreamReader(connection.openInputStream(),parser, this );
    //m_writer=new StreamWriter(connection.openOutputStream());
    }
    public void connect(){
    if(t==null){
    t=new Thread(this);
    t.start();
    }
    }
    public void unsecureConnect() throws Exception{
    String connectorURL ="socket://"+"yahoo.com:7070";
    //System.out.println(".......................connectorURL="+connectorURL);

    connection = (StreamConnection) Connector.open( connectorURL );
    HelloCanvas.status="Connected";
    notifyConnect();
    }
    public void run(){
    try{
    unsecureConnect();
    }catch(Exception e){
    System.out.println("coming here.in exception......................");
    }
    }
    }


    Thanks in advance
    Rijwan

  8. #8
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: Problem in multithreading while trying to connect server using SOCKET(J2ME Apps)

    Hi,
    Did u check the network monitor in your WTK while it gets connected to the server....
    Just check whether the connection process is complete...

    I think something not acceptable is happening there.

    Thanks
    Soku

Similar Threads

  1. j2se server j2me client bluetooth connection problem
    By bepolat in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2010-07-14, 11:05
  2. problem to connect server in Nokia 5300
    By AshutoshG in forum Mobile Java General
    Replies: 3
    Last Post: 2007-11-26, 23:41
  3. Nokia 6600 Socket Server send delay Problem
    By dicson_hu in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-31, 07:37
  4. connect function is giving problem
    By vinayakak in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2005-03-03, 09:29
  5. Problem Starting the server
    By Nokia_Archived in forum WAP Servers
    Replies: 1
    Last Post: 2002-05-14, 18:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×