Quote:
Originally Posted by klay_8 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.