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

IDEAL VOL-CON XL Voltage Meter/Continuity/Solenoid Tester Wiggy
$25.0
IDEAL VOL-CON XL Voltage Meter/Continuity/Solenoid Tester Wiggy  pictureGreenlee Touchless AC Voltage Indicator 2010
$71.79
Greenlee Touchless AC Voltage Indicator 2010 pictureMultimeterTriple Tree 6000 Counts PM18C AC DC Voltage Current Resistance Test...
$34.8
MultimeterTriple Tree 6000 Counts PM18C AC DC Voltage Current Resistance Test... pictureYeeco 0.56'' DC 3.2-30V Digital Voltmeter Voltage Tester Gauge Green Bright L...
$10.8
Yeeco 0.56'' DC 3.2-30V Digital Voltmeter Voltage Tester Gauge Green Bright L... pictureBaomain H7EC-BLM 0 - 999999 Counting Range No-voltage Required Digital Counter
$12.8
Baomain H7EC-BLM 0 - 999999 Counting Range No-voltage Required Digital Counter picture






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