View Single Post
Old 07-28-2009, 02:18 PM   #6 (permalink)
capndurk
New Member
 
Join Date: Jun 2009
Model: 7100T
PIN: N/A
Carrier: hi
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's my code for the server:

Code:
// byte[] data;
Socket s = ss.accept();
OutputStream os = s.getOutputStream();
PrintWriter pw = new PrintWriter(os);
pw.print(data.length);
pw.print('\n');
pw.flush();
os.write(data, 0, data.length);
os.flush();
And for the blackberry app:

Code:
SocketConnection sc = (SocketConnection) Connector.open("socket://<ip>:5000;deviceside=true");
InputStream is = sc.openInputStream();

// get image size from server
String sizeStr = "";
while((c = (char) is.read()) != '\n')
{
    sizeStr = sizeStr + String.valueOf(c);
}
int size = Integer.parseInt(sizeStr);

// get the data
byte[] data = new byte[size];
is.read(data, 0, size);

// create the bitmap
Bitmap b = Bitmap.createBitmapFromBytes(data, 0, data.length, 1);
Offline   Reply With Quote