package androidclient.test;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class AndroidClient_Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
//System.out.println("Has requested");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_android_client_);
//System.out.println("Has requested");
try {
java.net.Socket sc = new Socket(InetAddress.getByName("192.168.1.100"),2024);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Has requested");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_android_client_, menu);
return true;
}
}
The application has run into server. It has output in the monitor. But after I start client, it can not connect server. I also add some input sentence in oncreate() method. It has no response and did not output exception.
Could anyone give me a guide? Thanks very much!
You have to use the socket.getInputStream() and socket.getOutputStream to communicate via the socket.
See the client example on http://zerioh.tripod.com/ressources/sockets.html