BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-10-2009, 05:52 AM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Model: 9000
PIN: N/A
Carrier: optus
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default socket communication

Please Login to Remove!

hi guys,



I am trying to make a simple socket connection (very basic) I tried this:

class ss extends UiApplication {
public static String URL = "socket://xxx.xxx.xxx.xxx:8010;deviceside=true;apn=internet; ";
StreamConnection conn = null;
OutputStreamWriter _out;

public static void main(String[] args)
{
ss theApp = new ss();
theApp.enterEventDispatcher();
}

ss() {
MainScreen mainScreen = new MainScreen();

ButtonField button1 = new ButtonField("Send")
{
protected boolean invokeAction(int action)
{

try
{
conn = (StreamConnection)Connector.open(URL);
_out = new OutputStreamWriter(conn.openOutputStream());
String str = "AbcdefgAbcdefgAbcdefgAbcdefgAbcdefgAbcdefgAbcdefg ";
char[] cArray = str.toCharArray();
int length = str.length();
_out.write(cArray,0,length);

// I tried also this :_out.write(cArray); and this :_out.write(str); and also this: _out.write(str,0,length);
}
catch (Exception s){ }
return true;
}
};
mainScreen.add(button1);
pushScreen(mainScreen);
}
}



it connects, but I receive char by char on the server, I dont receive the whole string,



N.B.

I use BlackBerry 9000.



please help



thanks
Offline  
Old 06-14-2009, 06:12 PM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2009
Location: CANADA
Model: 9000
PIN: N/A
Carrier: Rogers
Posts: 64
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

And flush() doesn't help either?
Offline  
Old 06-14-2009, 07:40 PM   #3 (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

Quote:
Originally Posted by klay_8 View Post
hi guys,



I am trying to make a simple socket connection (very basic) I tried this:

Code:
class ss extends UiApplication {
    public static String URL = "socket://xxx.xxx.xxx.xxx:8010;deviceside=true;apn=internet;";
    StreamConnection conn = null;
    OutputStreamWriter _out;

     public static void main(String[] args)
    {       
        ss theApp = new ss();       
        theApp.enterEventDispatcher();
    }
   
    ss() { 
     MainScreen mainScreen = new MainScreen();

     ButtonField button1 = new ButtonField("Send")
        {
            protected boolean invokeAction(int action)
            {
                 
               try
                    {
                        conn = (StreamConnection)Connector.open(URL);
                        _out = new OutputStreamWriter(conn.openOutputStream());
                        String str = "AbcdefgAbcdefgAbcdefgAbcdefgAbcdefgAbcdefgAbcdefg";
                        char[] cArray = str.toCharArray();
                        int length = str.length();
                        _out.write(cArray,0,length); 

// I tried also this :_out.write(cArray); and this :_out.write(str); and also this: _out.write(str,0,length);     
                    }
                catch (Exception s){ }
                return true;
            }
        };
       mainScreen.add(button1);
       pushScreen(mainScreen);
      }
}


it connects, but I receive char by char on the server, I dont receive the whole string,



N.B.

I use BlackBerry 9000.



please help



thanks
Please post your code with the appropriate tags to preserve formatting, it makes it easier for others to help you. See this thread.

You should put network communications in their own thread, or at least off the event thread. The way you have written your code, when the socket IO blocks, it will cause your UI to freeze until the IO unblocks.

Data bocking structure is not preserved over TCP/IP links (even though that is what we see in most cases). The TCP stack my combine or break packets up depending on a number of factors. The cause of your character at a time problem could be occurring anywhere, but try putting the socked comms on a separate thread.
__________________
My other Blackberry is a PlayBook.
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

TDA7265 25W Audio Stereo Amplifier ST Micro Integrated Circuit - NOS Qty 1
$9.99
TDA7265 25W Audio Stereo Amplifier ST Micro Integrated Circuit - NOS Qty 1  pictureuPC575C2 NEC Audio Amplifier DIP IC 575C2 - NOS Qty 1
$7.99
uPC575C2 NEC Audio Amplifier DIP IC 575C2 - NOS Qty 1  pictureA4032P Sanyo Audio Amplifier DIP IC A4032 - NOS Qty 1
$9.99
A4032P Sanyo Audio Amplifier DIP IC A4032 - NOS Qty 1  pictureAerovox PA-113-1 2nd Detector Audio Amplifier Coupler Couplate PEC Module - USED
$9.99
Aerovox PA-113-1 2nd Detector Audio Amplifier Coupler Couplate PEC Module - USED pictureQty 1 AN5512 Audio Amplifier Integrated Circuit ECG1674 NTE1674 - NOS
$9.99
Qty 1 AN5512 Audio Amplifier Integrated Circuit ECG1674 NTE1674 - NOS picture






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