I've done this the other direction only, native to Dalvik.
Difficult to say much with what you've provided, and in principle.
At any rate, one thing of note is the server address 10.0.2.2 that you
use.
I use localhost, to remove any uncertainty about where the network
address might be known, or not. Try 127.0.0.0 instead.
Also, perhaps change the port number, just to be save nobody else is
sitting on the (likely) default port 8888 of your server.


On Jun 6, 1:41 am, galapogos <gois...@gmail.com> wrote:
> I managed to find some sample code for a simple unix server over 
> athttp://www.tutorialspoint.com/unix_sockets/socket_server_example.htmand
> cross compiled and run it in my rooted device. However, my client app
> doesn't seem to be sending anything to the server. Is there something I'm
> doing wrong?
>
>
>
>
>
>
>
> On Wednesday, June 6, 2012 2:17:50 PM UTC+8, galapogos wrote:
>
> > Hi,
>
> > I'm trying to get an Android app to talk to a native Android binary
> > service. Basically when I click a button, the app should send data to the
> > service, and receive some data back as well. I've written the Android
> > client app code, relevant portion below:
>
> >     Button.OnClickListener buttonSendOnClickListener = new
> > Button.OnClickListener(){
> >       //@Override
> >       public void onClick(View arg0) {
> >         Socket socket = null;
> >         DataOutputStream dataOutputStream = null;
> >         DataInputStream dataInputStream = null;
>
> >         try {
> >           socket = new Socket("10.0.2.2", 8888);
> >           dataOutputStream = new
> > DataOutputStream(socket.getOutputStream());
> >           dataInputStream = new DataInputStream(socket.getInputStream());
> >           dataOutputStream.writeUTF(textOut.getText().toString());
> >         } catch (UnknownHostException e) {
> >           // TODO Auto-generated catch block
> >           e.printStackTrace();
> >         } catch (IOException e) {
> >           // TODO Auto-generated catch block
> >           e.printStackTrace();
> >         }
> >         finally{
> >           if (socket != null){
> >             try {
> >               socket.close();
> >             } catch (IOException e) {
> >               // TODO Auto-generated catch block
> >               e.printStackTrace();
> >           }
> >         }
> >         if (dataOutputStream != null){
> >           try {
> >             dataOutputStream.close();
> >           } catch (IOException e) {
> >             // TODO Auto-generated catch block
> >             e.printStackTrace();
> >           }
> >         }
> >         if (dataInputStream != null){
> >          try {
> >             dataInputStream.close();
> >           } catch (IOException e) {
> >             // TODO Auto-generated catch block
> >             e.printStackTrace();
> >           }
> >         }
> >        }
> >     }};
>
> > When I run the app, it hangs and times out when I click the button. Turns
> > out it hangs on the socket connection. Is this because I have the wrong
> > address, or because there's no server listening to the same socket?
>
> > Also, are there any example code for a server I can cross compile for
> > Android that will talk to the Android app using sockets?
>
> > Thanks!

-- 
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