sockets - Get client IP in Wi-fi Direct connection in Android -
i'm developing application based on wifi direct connect 2 devices.
i followed demo in android documentation , read answers here @ stackoverflow similar problems.
my workflow follows, in order client ip on host i:
- create
serversocketin groupowner receives string (client ip) client on pre-determined port; - in client send ip through socket owner port;
- when owner receives ip shows button open gallery (like in client - in demo application)
something this:
@override public void onconnectioninfoavailable(final wifip2pinfo info) { this.getview().setvisibility(view.visible); // after group negotiation, assign group owner file // server. file server single threaded, single connection server // socket. if (info.groupformed && info.isgroupowner) { isgroupowner = true; // serversocket receives message client new messagereceivesocket(mcontentview.findviewbyid(r.id.btn_start_client), this).execute(); new filereceivesocket(getactivity()).execute(); } else if (info.groupformed) { mpeerip = info.groupowneraddress.gethostaddress(); // other device acts client. in case, enable // file button. mcontentview.findviewbyid(r.id.btn_start_client).setvisibility(view.visible); new filereceivesocket(getactivity()).execute(); // socket sends message owner socketutils.sendmessagetoserver(info.groupowneraddress.gethostaddress(), socketutils.server_message_port); } // hide connect button mcontentview.findviewbyid(r.id.btn_connect).setvisibility(view.gone); } my problem when disconnect both devices, , connect again both devices, receive error on client:
java.net.connectexception: failed connect /192.168.49.1 (port 8989) after 5000ms: isconnected failed: econnrefused (connection refused) the problem must serversocket not terminated, don't understand why or how should correct it.
Comments
Post a Comment