0

I work with and Android WiFiDirect app. I changed strongly given WiFiDirectDemo to make fallowing things:

  • group owner is the one to send data to rest of peers,
  • while pictre is sent, new activity is created,
  • moving picture with onTouch forces to create an xml fie.

The problem: while I start new service to send this xml (with onTouch in new Activity) I got connection refused to given ip and port, which to I've sent just sec. ago a picture.

I totaly can't handle that connection refused error, I suspect that IP is busy. While I click back button to previous activity it allows me to create an xml file and again shows connection refused.

I would like to know what to do to avoid this error:

E/Screen sharing: failed to connect to /192.168.49.10 (port 8988) after 5000ms: isConnected failed: ECONNREFUSED (Connection refused)

My permissions:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>    

UPDATE

Problem solved:

You start from one activity 2nd activity to which You put sent image. Now You want to again ask for service to send another data to sent IP and You can't. IP is busy and connection is refused BECAUSE Broadcast Receiver is still searching for message from 1st activity. What You need to do is to @Override OnResume method in 2nd activity like this.

    @Override
public void onResume(){
    super.onResume();
    receiver = new WiFiDirectBroadcastReceiver(manager, channel, MainActivity.activityMain);
    registerReceiver(receiver, intentFilter);
}        

Where WiFiBroadcast receiver is my broadcast receiver manager and channel is like in 1st activity and activityMain is simple Activity passed from 1st to 2nd like this

   public static MainActivity activityMain;

activityMain = this;            
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Adrian G
  • 9
  • 1
  • 4
  • Make sure all the necessary [permissions](http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html#permissions) are set up. – Onik Jan 08 '16 at 21:14
  • Thank You for clue, Ive pasted permisions into main thread. – Adrian G Jan 08 '16 at 21:25
  • I still can't solve this problem, but I've listed Threads and with every new file sending, new AsyncThread is created and old is not closed. – Adrian G Jan 10 '16 at 16:13

0 Answers0