Skip to main content

send image from computer to mobile

1 reply [Last post]
elkourd
Offline
Joined: 2010-06-03
Points: 0

i want to send image from computer to mobile using tcp socket
i tried the following code but it does not work
could any one help me

the code in the computer application (server)

InputStream input=new FileInputStream("dynamics.jpg");

byte[] buffer=new byte[1024];
int readData;
while((readData=input.read(buffer))!=-1){

output.write(buffer,0,readData);
}

the code in the mobile

int len = is.available(); //where is openInputStream();
byte [] imgByte = new byte[len];
ByteArrayOutputStream bStr = new ByteArrayOutputStream();

int ch = 0;
while ( (ch = is.read()) != -1 ) {
bStr.write(ch);
}
is.close();

imgByte = bStr.toByteArray();
bStr.close();
Image imgRes = Image.createImage(imgByte, 0, imgByte.length);

imageItem.setImage(imgRes);

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
suntzu2007
Offline
Joined: 2010-05-25
Points: 0

"It does not work" is too vague. Please give details. From what I can see, you're neither trying to connect to the server, nor is the server listening for incoming connections...

If you're having problems understanding socket programming, then I suggest: http://java.sun.com/docs/books/tutorial/networking/sockets/