Hello,
Please help me with this problem
I'm trying to connect my Android app to a PC server using Socket. Unforunately, the PC server doesn't receive any connection request from the app (there's no connection between them). I'm running the app in android emulator.
I've seen many tutorials and discussions in the internet about this problem and I fellow them literally, but still having the same problem that I mentioned above.
Note: the android app is running on eclipse emulator and the PC server on netbeans
** the PC server source code:
public class server{
ServerSocket server;
public server() {
try
{
server =new ServerSocket(8000); // create server socket
Socket socket = server.accept(); // accept new connection request
System.out.println("The connection is active");
}
catch (IOException e)
{
System.err.println("error.... 1\n");
}
}
public static void main(String[] args) {
new server();
}
}
--------------------
**The android app source code (client):
public class Client extends Activity {
Button con;
Socket socket;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
con = (Button)findViewById(R.id.myButton);
con.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try
{
socket = new Socket("My_PC_IPAddress", 8000);
socket.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
});
}
@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_main, menu);
return true;
}
}
----------------
Note:This permission was added to the meinfest.xml
<uses-permission android:name="android.permission.INTERNET"/>
Please help me to solve this problem
Thank you
Please help me with this problem
I'm trying to connect my Android app to a PC server using Socket. Unforunately, the PC server doesn't receive any connection request from the app (there's no connection between them). I'm running the app in android emulator.
I've seen many tutorials and discussions in the internet about this problem and I fellow them literally, but still having the same problem that I mentioned above.
Note: the android app is running on eclipse emulator and the PC server on netbeans
** the PC server source code:
public class server{
ServerSocket server;
public server() {
try
{
server =new ServerSocket(8000); // create server socket
Socket socket = server.accept(); // accept new connection request
System.out.println("The connection is active");
}
catch (IOException e)
{
System.err.println("error.... 1\n");
}
}
public static void main(String[] args) {
new server();
}
}
--------------------
**The android app source code (client):
public class Client extends Activity {
Button con;
Socket socket;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
con = (Button)findViewById(R.id.myButton);
con.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try
{
socket = new Socket("My_PC_IPAddress", 8000);
socket.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
});
}
@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_main, menu);
return true;
}
}
----------------
Note:This permission was added to the meinfest.xml
<uses-permission android:name="android.permission.INTERNET"/>
Please help me to solve this problem
Thank you