[android-developers] Re: App talking to native ARM binary via sockets
I managed to find some sample code for a simple unix server over at http://www.tutorialspoint.com/unix_sockets/socket_server_example.htm and 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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home