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

(1) MC3242AL MOT MC32 SERIES 14 LINE TO 1 LINE MULTIPLEXER INVERTED OUTPUT CDIP
$8.95
(1) MC3242AL MOT MC32 SERIES 14 LINE TO 1 LINE MULTIPLEXER  INVERTED OUTPUT CDIP pictureTOSHIBA Transistor Inverter VF-S9N VFS9S-2004PL-WN VF-S9 1PH/ 200V/ 0.4kW
$95.0
TOSHIBA Transistor Inverter VF-S9N VFS9S-2004PL-WN VF-S9 1PH/ 200V/ 0.4kW pictureChicago Electric Inverter 130Amp/90Amp 220V TIG Arc Welder 91811
$189.0
Chicago Electric Inverter 130Amp/90Amp 220V TIG Arc Welder 91811 picture135 Amp Arc Stick Welder IGBT Inverter Welding Soldering Machine 110V
$139.0
135 Amp Arc Stick Welder IGBT Inverter Welding Soldering Machine 110V picture115 Amp Arc Stick Welder IGBT Inverter Welding Soldering Machine
$119.0
115 Amp Arc Stick Welder IGBT Inverter Welding Soldering Machine picture






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