Yoavst
Yoavst

Reputation: 195

WifiP2pInfo.groupOwnerAddress.getHostAddress() wrong IP

I've got two devices - Note 3 (N9005) and G Pad 8.3 (also tested with Nexus 4 instead of the note 3, same results).
When I create a Wifi P2P group when the Note 3 is the group owner, on the G Pad (client) the method WifiP2pInfo.groupOwnerAddress.getHostAddress() return the right IP. But when I create a Wifi P2P group when the G Pad is the group owner, on the Note 3 (client) the method return wrong IP address!

here is an ipconfig from the G Pad as group owner with the right ip address:

ipconfig on the tablet while being group owner

and here is the ECONNREFUSED exception on the Note 3 when trying to connect the given ip address:

11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ java.net.ConnectException: failed to connect to /192.168.49.1 (port 7958) after 5000ms: isConnected failed: ECONNREFUSED (Connection refused)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ at libcore.io.IoBridge.isConnected(IoBridge.java:223)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ at libcore.io.IoBridge.connectErrno(IoBridge.java:161)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:112)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:460)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ at java.net.Socket.connect(Socket.java:833)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ at com.yoavst.wifidirectlib.WifiP2P$5.run(WifiP2P.java:237)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ Caused by: libcore.io.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ at libcore.io.IoBridge.isConnected(IoBridge.java:208)
11-25 21:04:53.264    4817-4986/com.example.wifidirect.app W/System.err﹕ ... 7 more

192.168.49.1 is not 192.168.49.129

Here are also the code, but I don't think it is the problem:

Client

Socket socket = new Socket();
                    socket.setReuseAddress(true);
                    socket.connect((new InetSocketAddress(info.groupOwnerAddress.getHostAddress(), PORT_GET_IP)), 5000);
                    OutputStream os = socket.getOutputStream();
                    ObjectOutputStream oos = new ObjectOutputStream(os);
                    oos.writeObject(HANDSHAKE_STRING);
                    oos.close();
                    os.close();
                    socket.close();

Server

ServerSocket serverSocket = new ServerSocket(PORT_GET_IP);
                            Socket client = serverSocket.accept();
                            ObjectInputStream objectInputStream = new ObjectInputStream(client.getInputStream());
                            Object object = objectInputStream.readObject();
                            if (object.getClass().equals(String.class) && object.equals(HANDSHAKE_STRING)) {
                                otherDeviceINetAddress = client.getInetAddress();
                                initClient(client.getInetAddress().toString().substring(1));
                            }

Upvotes: 1

Views: 1973

Answers (1)

Roberto Betancourt
Roberto Betancourt

Reputation: 2515

According to your last comment, you can't set the device you want as the group owner. What steps have you taken so far? Per the android documentation, you can try to set the Group Owner when you first try to connect via the WifiP2pConfig class setting the groupOwnerIntent However, this is not 100% reliable and the system may end up deciding who the group owner will be, specially if you had already established a connection in the past and the group information has been persisted.

Upvotes: 2

Related Questions