I am trying to connect to java (server) from android phone (client). Server code:
import java.net.*;
/**
* Created by mwalko on 07.06.16.
*/
public class Main {
public static void main(String[] args)
{
try
{
ServerSocket sock = new ServerSocket (8601);
for (;;)
{
Socket newsock = sock.accept();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Then I can talk with it by cURL:
curl localhost:8601
Hello :: enter QUIT to exit
From server: GET / HTTP/1.1.
From server: Host: localhost:8601.
From server: User-Agent: curl/7.47.0.
From server: Accept: */*.
From server: .
But when I try to connect from android which works on this code (I also added <uses-permission android:name="android.permission.INTERNET" />
to AndroidManifest.xml):
new Thread() {
@Override
public void run() {
try {
Socket s = new Socket("192.168.1.102", 6000);
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
I get an error:
06-07 20:09:03.530 7319-7319/com.example.root.client E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.root.client, PID: 7319
06-07 21:45:20.990 25482-25520/com.example.root.client W/System.err: java.net.ConnectException: failed to connect to /192.168.1.102 (port 6000): connect failed: ECONNREFUSED (Connection refused)
I can ping 192.168.1.101 from phone. Why can't I connect to server, are there any bugs?