I am testing the communication between the Android and my Laptop.
I have a Lan connection and I shared the Internet through the laptops WiFi
Now I have created a Server on laptop with the code
public void run()
{
try {
server_soc = new ServerSocket(1234);
display.append("Server Started on port : " + server_soc);
display.append("\nWaiting for client to connect ");
while(true){
cli=server_soc.accept();
display.append("\nClient connected ");
Accept_Client accept_client=new Accept_Client(cli);
accept_client.start();
}
the server starts successfully.
I have to connect an android client (android 4.0.4) to this server. I am not able to connect to this Server. What should be the IP used to connect to this server ?
Client (android) code :
Connect.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
Server = new Socket("10.0.2.2",1234);
Server_Msg.setText("connected to Server ");
} catch (Exception e) {
e.printStackTrace();
}
}
});
I tried all the IPs :192.168.137.1, 123.238.143.130 What should be the IP ?
I have even set up port forwarding in my wireless router. Do I need to do anything in firewall ? Please suggest !
In case of Server-client system using real android device you just have to make sure that the port you are listening to is added in firewall.
The server will listen to that port and all the connections coming on that port from any IP will be connected.