BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 01-11-2009, 05: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, 04: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, 04: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





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