Android ServerSocket accepts wifi hotspot

I have an Android device that works as a hotspot (aka wifi hotspot) and runs this code:

    serverSocket = new ServerSocket(serverPort);

    serverSocket.setReuseAddress(true);

    while (RUNNING) {
        try {
            final Socket socket = serverSocket.accept();

      

I will have some other client device connected to this wifi hotspot of the device and try to connect to the socket and it fails.

The IP address of the AP is like 192.168.43.1 ... so I try to connect from the client device to 192.168.43.1:8080 and it won't work.

However , if both devices are connected to a different Wi-Fi network, serverSocket.accept (); will work great! I am using port 8080.

Should I tell the server socket to accept on interface "ap0"? (Can I do this?) Is this a firewall issue on the Android device?

Any solutions / ideas / suggestions are appreciated!

Edit:

I changed the port to 8988 and now it works fine! ... Could this be a firewall issue? Any ideas on how to navigate this issue?

+3


source to share


1 answer


Yes you also need to open a socket on the server side.



You should try the Android example WiFiDirectDemo

available in Android Legacy: \Android\android-studio\sdk\samples\android-19\legacy

just import it into the environment and try it.

0


source







All Articles