BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-06-2009, 04:05 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Nov 2007
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 61
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default problem in socket connection

Please Login to Remove!

hi there,
I am developing a chat app using socket connection ..there is no problem when am using 4.2 os for send and getting response but when am using 4.5.0.40 os my phone reboots automatically when am sending data two or three times....i upgrade newer version to 4.5.0.135 but since am facing the same problem.someone please help me.....
following is my code

This is my socketconnection implementation
Code:
        void socketConnect()
        {                               
            urlAddress = "socket://"+ipAddress+":"+portNo;// + ";deviceside="+tcpenable;   
            try 
            {
                 streamConnection  = (StreamConnection) Connector.open(urlAddress);                               
                _inputStreamReader = new InputStreamReader(streamConnection.openInputStream());
                _outputStreamReader = new OutputStreamWriter(streamConnection.openOutputStream());                                       
            }
            catch (Exception ex)
            {
                
                
            }
        }
this is my sending data method


Code:
  public void senddata(String data)
        {
            try 
            {
                synchronized(this)
                {                
                 int length = data.length();
                _outputStreamReader.write(data,0,length);
                _outputStreamReader.flush();   
                }
            } 
            catch(Exception ex)
            {               
                 
            }
        }

Last edited by sunnan : 03-06-2009 at 04:32 AM.
Offline  
Old 03-06-2009, 09:06 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

When you send and receive data are you doing that on the event thread? That can cause problems when the latency of the communications delays the event thread from responding to events.
Offline  
Old 03-07-2009, 06:18 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Nov 2007
Model: 8100
PIN: N/A
Carrier: vodafone
Posts: 61
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

First of all Thank you very much for your reply.....i am using seperate thread for connection ...below is my complete code ...when i send message continously from my 4.5 os my phone reboots automatically.....also i ll be very helpful if some one test my app in any 4.5 os and reply me.....

Code:
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.MainScreen;


public class testsocket extends UiApplication
{
    static homescreen mainscreen;
    static LabelField lab;
    static ConnectThread connectThread = null;
    
    public static void main(String[] args) 
    {
        new testsocket().enterEventDispatcher();
    }
    
    testsocket() 
    {
        mainscreen = new homescreen();        
        pushScreen(mainscreen);
    }
    
    static class homescreen extends MainScreen 
    {
                  
        public homescreen()
        {
            setTitle(new LabelField("Test", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH));
        }

        protected void makeMenu(Menu menu, int instance) 
        {
            MenuItem item = new MenuItem("start", 30, 2)
            {

                public void run()
                {
                    connectThread = new ConnectThread("64.33.22.11", "6012","test123", "pass123");
                    connectThread.start();
                }
            };
            menu.add(item);


            MenuItem items = new MenuItem("send", 50, 4)
            {
                public void run() 
                {
                    String data = "testing";
                    connectThread.senddata(data);
                }
            };
            menu.add(items);

        }
    }
    static class ConnectThread extends Thread 
    {      
       
        private String urlAddress="";
        private String userName="";
        private String passWord = "";
        private String ipAddress;
        private String portNo;
        private InputStreamReader _inputStreamReader;
        private OutputStreamWriter _outputStreamReader;
        private StreamConnection streamConnection = null;
         
       public ConnectThread(String IPaddress,String port,String userName,String passWord)
       {
            this.ipAddress=IPaddress;
            this.portNo=port;
            this.userName = userName;
            this.passWord = passWord;            
       }       
      public void close()
      {
         new Thread(new Runnable() 
         {
             public void run()
             {
                 try
                 {
                     if (_inputStreamReader != null)
                     {
                         _inputStreamReader.close();
                         _inputStreamReader = null;

                     }
                     if (_outputStreamReader != null)
                     {
                         _outputStreamReader.close();
                         _outputStreamReader = null;
                     }
                     if (streamConnection != null)
                     {
                         streamConnection.close();
                         streamConnection = null;
                     }

                 }
                 catch (Exception ex)
                 {
                     
                 }
             }
         }).start();
     }

        void socketConnect()
        {                               
            urlAddress = "socket://"+ipAddress+":"+portNo;
            try 
            {
                 streamConnection  = (StreamConnection) Connector.open(urlAddress);                               
                _inputStreamReader = new InputStreamReader(streamConnection.openInputStream());
                _outputStreamReader = new OutputStreamWriter(streamConnection.openOutputStream());                                       
            }
            catch (Exception ex)
            {                                
            }
        }        
     
      public void senddata(String data)
        {
            try 
            {
                synchronized(this)
                {                
                 int length = data.length();
                _outputStreamReader.write(data,0,length);
                _outputStreamReader.flush();              
                }
            } 
            catch(Exception ex)
            {                                
            }
        }      
      public void run()
        {                                 
           socketConnect();                                                                                 
        }                     
}
}

Last edited by sunnan : 03-07-2009 at 06:19 AM.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.