BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 01-11-2009, 06:43 AM   #1 (permalink)
New Member
 
Join Date: Jan 2009
Model: 8800
PIN: N/A
Carrier: /
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Image to BlackBerry over socket connection

Please Login to Remove!

Hi!

I'm develompin BlackBerry application for stock values. I'we alredy have server and my blacbkerry connected to this server over socket connection

connection to server:
private String URL = "socket://localhost:64208;deviceside=true";
connection = (StreamConnection)Connector.open(URL);
_out = new OutputStreamWriter(connection.openOutputStream());
_in = new InputStreamReader(connection.openInputStream());

Connection is working fine (sending strings to server and back).
Now i want to display stock value chart on blackberry. I generate chart image on my server (BufferedImage) (can allso generate other type of image if i want) so now i wonder how to send image from server to blackberry usnig my stream connection and display this image on blackberry (BitmapField component).

It would be nice if someone gave me example how to do this.

ty!
Kristjan
Offline  
Old 01-17-2009, 05:26 AM   #2 (permalink)
New Member
 
Join Date: Jan 2009
Model: 8800
PIN: N/A
Carrier: /
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

after days of work i finaly made it
here is tehe code:

Server side
Code:
//  pout is print writer...
Socket s = ss.accept();
OutputStream os = s.getOutputStream();
PrintWriter pout = new PrintWriter(os, true);
//


// this is our buffered image
BufferedImage slika;
                                     
ByteArrayOutputStream bas = new ByteArrayOutputStream();
ImageIO.write(slika,"JPEG", bas); // write image into ByteArrayOutputStream
byte[] data = bas.toByteArray();
pout.println(String.valueOf(data.length));  // sending image length to blackberry
os.write(data, 0, data.length); // sending image to blackberry
os.flush();

Code on blackberry:

Code:
//
InputStream is
//

// get image size from server
String answer3 = "";
char k3;
do
{
    k3 = (char) _in.read();
    answer3 = answer3+ String.valueOf(k3);
}while(k3 != '\n');

int velikost = Integer.parseInt(answer3.toString());

byte[] data = new byte[velikost];
is.read(data, 0, velikost);   // read image             

EncodedImage image = EncodedImage.createEncodedImage(data,0,data.length);
Bitmap b = image.getBitmap();
BitmapField picture = new BitmapField(b);

mainScreen.add(picture); // adding picture to main screen
Offline  
Old 02-02-2009, 05:41 AM   #3 (permalink)
New Member
 
Join Date: Sep 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi i too tried receiving image from server using sockets am getting the image using ur code, but the transfer speed is too slow. A 10kb image is taking around 40 seconds. Is this a normal socket speed? If not is there anyways to improve the data transfer speed. (Am using InputStreamReader and its read() method is wat s taking time). I now need to tranfer 2Mb data which at this speed would be highly impossible.

Thanks & regards
Mike.
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

100pcs 4.7uF 400V Low Impedance Electrolytic Capacitor for Computer Motherboard
$8.84
100pcs 4.7uF 400V Low Impedance Electrolytic Capacitor for Computer Motherboard pictureVintage Gould Type BJB Fan Motor 115V, 60 Hz 1212581-01C IMPEDANCE CSA WORKS 19P
$30.0
Vintage Gould Type BJB Fan Motor 115V, 60 Hz 1212581-01C IMPEDANCE CSA WORKS 19P pictureSpeaker/Line Impedance Tester
$35.0
Speaker/Line Impedance Tester picture10pcs 120uF 25V 5x15mm Jamicon TL 25V120uF Longlife low impedance capacitor
$1.69
10pcs 120uF 25V 5x15mm Jamicon TL 25V120uF Longlife low impedance capacitor pictureGeneral Radio 1650-B Impedance Bridge
$343.88
General Radio 1650-B Impedance Bridge picture






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