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

Pair Of Two Vintage Mac Tools Wrenches SAE Good Condition
$4.99
Pair Of Two Vintage Mac Tools Wrenches SAE Good Condition pictureVintage Mac Tools No. 200 Dial Indicator Set
$59.99
Vintage Mac Tools No. 200 Dial Indicator Set pictureNew Vintage Velocette MAC 350cc Single 1949 Petrol Fuel Gas Tank
$290.0
New Vintage Velocette MAC 350cc Single 1949 Petrol Fuel Gas Tank pictureVintage Mac Allied Hex Rethreader Dies - # TR-8-U in Case
$15.0
Vintage Mac Allied  Hex Rethreader Dies - # TR-8-U in Case  pictureVtg MAC Tools X106 5/16" Chrome SAE Socket 3/8" Drive 6 Point Sabina Ohio USA
$7.0
Vtg MAC Tools X106 5/16






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