Hi,

I am trying to send an image, knowing its URI, to a server using java
sockets. I am doing the following but doesn't look like its working as
I can't receive anything on the server side.

Main code:

// FileClient is the class that represents Client side socket code.

Intent ss = new Intent(this, FileClient.class);
ss.setData(uri);   //uri is the URI of the selected picture from
within the gallery
startActivity(ss);


FileClient class:

public class FileClient extends Activity {

           private Uri sendImageURI = null;

           @Override
           public void onCreate(final Bundle icicle) {
                 super.onCreate(icicle);

                 int serverPort = 8008; //port on server
                 String address = "xxx.xxx.xx.xx"; // this is the IP
address of the server.

            try {

                Socket socket = new Socket("xxx.xxx.xx.xx", serverPort); //
create a socket with the server's IP address and server's port.
                System.out.println("Connected to Client");

                // Retreive the URI to the selected picture
                sendImageURI = getIntent().getData();

                FileInputStream fis = new FileInputStream
(sendImageURI.toString()); // I AM NOT SURE ABOUT THIS PART..... NEED
HELP HERE!!

                byte[] buffer = new byte[fis.available()];

                fis.read(buffer);

                ObjectOutputStream oos = new ObjectOutputStream
(socket.getOutputStream());
                oos.writeObject(buffer);

                oos.flush(); // flush the stream to ensure that the
data reaches the other end.


               }     catch(Exception x) {
            x.printStackTrace();
                    }

         }

}


Server code:
..................................
ObjectInputStream ois = new ObjectInputStream
(clientSocket.getInputStream());
byte[] buffer = (byte[])ois.readObject();
FileOutputStream fos = new FileOutputStream("C:\\Downloaded\
\picture.jpg");
fos.write(buffer);
....................

Any help would be appreciated.

Thanks,

Abhi

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to