Android Socket Programming?
Asked Answered
T

2

7

I need a little bit help regarding to android socket programming. I had made a server-client prototype using java socket programming. In server client scenario , I am sending commands from 1-10 and sever do some task according to command received from client. e.g. when server receives a command it sever will send a bufferedImage to the client. Its (java prototype) is working fine. In this scenario, both server and client a java desktop applications, Now I want to make android as a client. Can someone help me in this regard or suggest me good resources of android socket programming?

(Please note BufferedImage class is not supported by Android.)

Throe answered 6/5, 2011 at 7:18 Comment(0)
K
8

There is no problem in porting your application. Android runs on Java, which very similar to desktop version. All you need is to migrate BufferedImage to simple byte array, and to use ImageIO on your server side.

Kuster answered 6/5, 2011 at 7:22 Comment(6)
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write( bImage, "png", baos ); byte[] data = baos.toByteArray(); server.getOutputStream().write(data);Throe
how I can receive byte[] at client side(android device)?Throe
I assume that client is a socket on your android device. Then: ByteInputStream stream = new ByteInputStream(client.getInputStream()); byte[] img = stream.toByteArray();Kuster
there is no ByteInputStream class in android, are you means ByteArrayInputStream?Throe
What do you mean? An error? Or what? Better to accept the answer and ask another one with the code shown.Kuster
well not an error but its not working, anyways thanks for your help.Throe
S
0

@Op. Do note that you on the Android device probably also want to keep a PARTIAL_WAKE_LOCK while you are downloading the image.

Spinous answered 6/5, 2011 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.