BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-30-2008, 08:37 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default TCP with , , , ,...

Please Login to Remove!

hey there,
i've got a tcp connection and i want to display some names or something.
now i've git the problem, that an the place for an stands a symbol or something.

i send the data to the BB as an ASCII string, so i have to encrypte this string on BB again, but how?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 10-30-2008, 08:51 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

Looks like a character encoding issue. The BlackBerry uses UTF-8 by default - check and see what kind of encoding is being used on the other end of the socket. Probably 8859 if it is a Windows system.

You'll need to take the byte array and convert to string with the correct encoding, or change the encoding on the other end to UTF-8.

See API docs for String:

public String(byte[] bytes,String enc)
Offline  
Old 02-27-2009, 04:58 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, i have tried this one here:
PHP Code:
 do {
                        
ch = (byte)is.read();
                        
sb.append((charch);
                    } while (
is.available() > 0);
                         
String myErg = new String(sb.toString().getBytes(),"UTF8");
                            
myBuffer += myErg
all '', '', '' and '' are displayed as '??'...
i have tried UTF-8, UTF8 and ASCII.

the sender is a windows-service, sending in ASCII...

maybe someone can help me

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after

Last edited by hibbert : 02-27-2009 at 05:08 AM.
Offline  
Old 03-01-2009, 02:40 PM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2008
Location: Paris, France
Model: None
PIN: N/A
Carrier: None
Posts: 36
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You must set the "source" encoding, which is probably ISO-8859-1...
Offline  
Old 03-10-2009, 07:59 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
ok, and what if i can't change the source encoding? What should i do then? is there an option which i can change on the BES or on the BB?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 03-10-2009, 02:37 PM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2008
Location: Paris, France
Model: None
PIN: N/A
Carrier: None
Posts: 36
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

As a matter of fact, I think your code is wrong before the "new String()" bit : when you "append" the read byte to "sb" (which, I assume, is a string buffer), the wrong conversion has already happened.

What you need to do is read the data in a byte array and convert this byte array to a String.
Offline  
Old 03-11-2009, 06:43 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, thanks, but that won't work, because of this one here:
i have printed out every char, and look what happens:
i get this string: 613 Z??hler
and here are the char-numbers:
6 --> 54
1 --> 49
3 --> 51
 --> 23
Z --> 90
? --> -61
? --> -92
h --> 104
l --> 108
e --> 101
r --> 114

so the "" as got two numbers. so i can convert the inputstream at any position, and it won't work, because the "" has got two characters.

so what can i do??

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 03-11-2009, 02:51 PM   #8 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2008
Location: Paris, France
Model: None
PIN: N/A
Carrier: None
Posts: 36
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Characters on 2 bytes just mean it's an UTF-8 encoding. And imply that you will have to explicitly set the encoding when doing the conversion.

That does not change a thing about what I wrote above: fill a byte array with the text and do the conversion on the whole array. You don't have any other option except decoding the UTF-8 chars yourself.
Offline  
Old 03-12-2009, 07:47 AM   #9 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
ok, but how do i create a dynamed byte-array? and how do i convert this one to a new string?

thanks again.
hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 03-13-2009, 05:48 AM   #10 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

ByteArrayOutputStream
__________________
java developer, Devinto, hamburg/germany
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.