BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-10-2009, 10:56 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2009
Model: 8100
PIN: N/A
Carrier: AIRTEL
Posts: 25
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Socket writing and reading image on blackberry device

Please Login to Remove!

Hi,
I am trying to write a simple socket program in which the server socket as well as client socket also remain on device. I am starting the server socket and then starting the client socket which writes the image to the outputstream and the listening server socket will fetch the byte data from the inputstream and display it.
I am in confusion whether to use outputstream or dataoutputstream to write the data. Somebody in forums told that outputstream is not good for writing the image data.

Please provide me the sample code in which i had to write and read the image data from the blackberry device.
Client Side Code
SocketConnection sock = (SocketConnection)Connector.open("socket://sample-PC:5680;deviceSide=false");

InputStream is = sock.openInputStream();
OutputStream os =sock.openOutputStream();
Bitmap bmp = Bitmap.getBitmapResource("raj-logo-hai.png");
int height=bmp.getHeight();
int width=bmp.getWidth();
int[] rgbdata = new int[width*height];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);

Graphics g = new Graphics(bmp);
bmp.getARGB(rgbdata,0,width,0,0,width,height);
for (int i = 0; i < rgbdata.length ; i++) {
if (rgbdata[i] != -1) {
dos.writeInt(i);
dos.flush();
}
}
bos.flush();
bos.close();
sock.close();

server side code
ServerSocketConnection ss =(ServerSocketConnection)Connector.open("socket://:"+5680+";deviceSide=true");

str=new StringBuffer();
while(true){
SocketConnection incoming = (SocketConnection)ss.acceptAndOpen();

InputStream is =incoming.openDataInputStream();
OutputStream os = incoming.openOutputStream();
byte[] responseData = new byte[82000];
int length1 = 0;
StringBuffer rawResponse = new StringBuffer();

while (-1 != (length1 = is.read(responseData)))
{
rawResponse.append(new String(responseData, 0, length1));
}
final String result = rawResponse.toString();
byte[] dataArray = result.getBytes();
bitmap = EncodedImage.createEncodedImage(dataArray, 0,
dataArray.length);
BitmapField picture = new BitmapField(bitmap.getBitmap());

add(picture);
updateDisplay();
Offline  
Old 01-08-2010, 06:22 AM   #2 (permalink)
New Member
 
Join Date: Dec 2009
Model: 7100T
PIN: N/A
Carrier: 7100T
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by satyarajasekhar View Post
Hi,
I am trying to write a simple socket program in which the server socket as well as client socket also remain on device. I am starting the server socket and then starting the client socket which writes the image to the outputstream and the listening server socket will fetch the byte data from the inputstream and display it.
I am in confusion whether to use outputstream or dataoutputstream to write the data. Somebody in forums told that outputstream is not good for writing the image data.

Please provide me the sample code in which i had to write and read the image data from the blackberry device.
Client Side Code
SocketConnection sock = (SocketConnection)Connector.open("socket://sample-PC:5680;deviceSide=false");

InputStream is = sock.openInputStream();
OutputStream os =sock.openOutputStream();
Bitmap bmp = Bitmap.getBitmapResource("raj-logo-hai.png");
int height=bmp.getHeight();
int width=bmp.getWidth();
int[] rgbdata = new int[width*height];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);

Graphics g = new Graphics(bmp);
bmp.getARGB(rgbdata,0,width,0,0,width,height);
for (int i = 0; i < rgbdata.length ; i++) {
if (rgbdata[i] != -1) {
dos.writeInt(i);
dos.flush();
}
}
bos.flush();
bos.close();
sock.close();

server side code
ServerSocketConnection ss =(ServerSocketConnection)Connector.open("socket://:"+5680+";deviceSide=true");

str=new StringBuffer();
while(true){
SocketConnection incoming = (SocketConnection)ss.acceptAndOpen();

InputStream is =incoming.openDataInputStream();
OutputStream os = incoming.openOutputStream();
byte[] responseData = new byte[82000];
int length1 = 0;
StringBuffer rawResponse = new StringBuffer();

while (-1 != (length1 = is.read(responseData)))
{
rawResponse.append(new String(responseData, 0, length1));
}
final String result = rawResponse.toString();
byte[] dataArray = result.getBytes();
bitmap = EncodedImage.createEncodedImage(dataArray, 0,
dataArray.length);
BitmapField picture = new BitmapField(bitmap.getBitmap());

add(picture);
updateDisplay();
you can anser me:server run on PC or BB other?
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

Allen Bradley, SLC 500, 1747-M11, 32K Flash EEPROM Memory, Very Good Condition
$42.95
Allen Bradley, SLC 500, 1747-M11, 32K Flash EEPROM Memory, Very Good Condition pictureAllen Bradley 2711-NM2 NIB EEPROM MEMORY CHIP SET
$199.0
Allen Bradley 2711-NM2 NIB EEPROM MEMORY CHIP SET picture258098 RCA IC-EEPROM 24C08 Integrated Circuit RCA
$5.99
258098 RCA IC-EEPROM 24C08 Integrated Circuit RCA picture4PCS AT24C256 Serial EEPROM I2C Interface EEPROM Data Storage Module PIC M113
$0.99
4PCS AT24C256 Serial EEPROM I2C Interface EEPROM Data Storage Module PIC M113 pictureAT24CXX EEPROM Board AT24C04 Serial I2C Memory Evaluation Development Module Kit
$4.99
AT24CXX EEPROM Board AT24C04 Serial I2C Memory Evaluation Development Module Kit picture






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