-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to connect [Error: failed to connect to /192.168.49.1 (port 8988) from /192.168.49.1 (port 37003) after 5000ms: isConnected failed: ECONNREFUSED (Connection refused)] #38
Comments
Hi @C-Thun You are trying to send multiple files at the same time (that's how In case if you want to send multiple files you should do it sequentially: file1 -> file2 -> file3 (only after successful transfer of I hope I gave you an answer on your question why it's not working. Try to rewrite your code and send files sequentially. Feel free to ask other questions if something is not clear :) |
So if i try and send one file, it should work, right? However, that still doesn't seem to explain why calling Upon testing with one file only (to prevent for the issue of race condition), I still get the same error. The exact same error. I can see that Any help, insight, etc would be helpful. I can give you exact logs from whatever source you want so if you need me to provide any such, do ask and I would be happy to provide you the details so that this issue can be fixed |
Hi, @C-Thun
That would be nice if you can share your logs from You described your issue, and I understand what is the problem. And, of course, this problem shouldn't exist. So attaching Android logs (Java) can help me significantly :) BTW, have you tried to switch you server/client devices? I mean run client code on "server" phone, and "client" code on server device? Merely change roles of devices. In this case you still receive the same error? |
I did change the roles of the devices multiple times but it didn't do anything different except for once when it did actually manage to send a message to the other device. Other than that one transmission, it didn't work regardless of which device was client and which was server. Will attach the ADB Logcat response in a few hours (away from my laptop right now) |
Here is the ADB Logcat. Steps done in sequence : -
In addition, for some reason it shows a FINE_LOCATION issue in adb logcat but I have provided both and for FINE_LOCATION in the Manifest and have provided the app with full location access (Allow all the time) after calling the location permission as asked from your code (And it shows that P2P mode can be used, isInitialised: true and startDiscoveringPeers successful |
As I see from logs the internal variable BTW, I don't see successful execution of react-native-wifi-p2p/android/src/main/java/io/wifi/p2p/WiFiP2PManagerModule.java Line 63 in 102e005
|
Also, you are right that |
Trying after reversing the devices, here are the adb logcat files after reversing the devices roles. Also, I got a doubt. |
I don't think so. |
The one on 01:49:44.409 is the output that is caused by problems in the Also, I am using USB cable (that came with the phone's charger) to debug the app. The soft exception would have been due to the crash I suppose. Also, wherever I have called |
Any updates? |
One interesting moment:
Why bridge has been destroyed? :) It happens before actual sending. Another moment:
Why it removes two times? In adb reverse:
Why so? I don't see any direct errors, to be honest... Could you edit your code in I know, my answer probably will not help you, since I don't know what is going wrong... |
So you mean adding more log statements in And yes, I am never able to create group despite following the exact same order that was in your documentation. Can the issue here also be caused by the fact that I'm using a rooted phone with a custom ROM? If yes, then I can retry running the code after reverting the devices to the OEM builds (I'm not sure why this would cause an issue but custom ROMs can sometimes have missing implementations of features) |
Yes, it may be useful to see, where the errors occur. You can try to wrap the body of
It can be, however I'm not sure... |
So it's definitely not due to the custom ROM. I reverted to the stock firmware and it still is not able to create the group. Maybe I can go for the suboptimal solution of connecting via QR codes and then sharing via TCP for now but would have really loved this to work. I'm completely stumped why this doesn't work. If you feel like, I can open source my app repo and you can take a look? Maybe you'll find some issues over there. Also, if you have time and are willing to collaborate, you could join in as a contributor to the app I'm making. If we can make it work with your API, then it can be a really nice Proof of concept for your library. I'm honestly in a slump right now and any help would be immensely helpful 😢 |
@C-Thun have you tried use this repo: https://github.com/kirillzyusko/react-native-wifi-p2p-example |
That was one of the first things I did and, if I recall correctly, even then I was not able to create group and it showed the same error even then.
I can try it once more today but if it doesn't work, I'll probably ask my friends to try my app on their devices (maybe it turns out to be a hardware issue) and the if even that works, I might probably have to just resort to the QR based solution. Thanks a lot for the help though. |
You can read more about error: https://developer.android.com/reference/android/net/wifi/p2p/WifiP2pManager#BUSY |
For sure, will look into it in some time. Do keep the issue open, if there is some update that helps me fix this issue, then I can let you know and hopefully this can help others who face this issue too. |
Good. At least one device now can create group successfully. The error seems to be the same as before. So I have to ask: did you call |
So, as you can see in the picture, the console output Getting connection info occurs while I'm calling import * as WiFiP2P from 'react-native-wifi-p2p';
const sendFiles = (files) => {
const nextFile = files.shift();
if (nextFile) {
console.log('Sending file ', nextFile.name);
return WiFiP2P.sendMessage(nextFile.name).then(WiFiP2P.sendFile(nextFile.uri)).then(_ => WiFiP2P.sendFiles(files));
} else {
return Promise.resolve();
}
}
export const sendFilesToServer = (macAddr, files) => {
console.log(files, macAddr);
files.forEach(file => {
WiFiP2P.connect(macAddr)
// Resolve connection details using getConnectionInfo
.then(() => WiFiP2P.getConnectionInfo())
.then(() => {
console.log('Sending Files');
return sendFiles(files);
})
.catch(err => console.log('Error occurred', err));
});
}
export const receiveFromClient = () => {
console.log('Can receive now');
// Receive file metadata using receiveMessage()
WiFiP2P.removeGroup(() => console.log('Removed old group'))
.then(() => {
console.log('Successfully created group');
return WiFiP2P.createGroup();
})
.then(() => {
console.log('Waiting for message');
return WiFiP2P.receiveMessage();
})
// .then(() => {
// return PermissionsAndroid.request(
// PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
// {
// 'title': 'Access to write',
// 'message': 'WRITE_EXTERNAL_STORAGE'
// }
// )
// })
// Receive file and store it based on the metadata
.then(message => {
console.log('Received message ', message);
return WiFiP2P.receiveFile('/storage/emulated/0/Music/', message);
})
.catch(err => console.log(err));
} |
Ooops, sorry, didn't notice it. |
But I can try to say in advance where is the problem :) |
So how do I encode them? Do I parse through the string and modify it or is there any built in library that can be used for the same? |
Try to use this package. Or try to search in google how to encode/decode URI. Maybe you could find better way :) But at the beginning you can "hardcode" this path. Just for checking whether my suggestion is working in your case or there are others problems as well. And if it works - try to find a long term solution :) |
Okay, then output from |
Here it is |
Did you miss a callback inside of promises chain?
Shouldn't be:
? |
Oops, I certainly missed the callback. Thanks for pointing that out. However, while correcting that mistake certainly helped remove the unnecessary error that was there because of the Promise chain, it still didn't resolve the ECONConnectionRefused thing. Here is how the thing looks after correcting for the callback and only that change. Also, thanks for pointing that out. It wasn't your function. Renamed it as well. However, the connection refused error persists Also, find attached the ADB Logcat output |
Now you are trying to send two files. It will not work. sendFile opens socket connection. And since you are trying send two files - second connection will be rejected because the port is already in usage. It's happening because you are sending files via forEach. And it sends files in parallel. But you should do it sequentially. Also connect and getConnectionInfo should be called not inside of for-loop. Try to send one file. I can assure, that it will work. Or try to send one message (without file). I also can assure that it will work perfectly. |
The sendFiles method that I have created will do it sequentially (I forgot to remove the for loop earlier. Fixed that) by recursively calling the sendMessage and sendFile functions only after the previous succeed. In addition, I've tried sending only one file but the same issue persists |
Could you attach logs from this case? |
Tried both of your recommendations. Here is the attached log file. If you feel like, you may view my app code (I made the repo public) Here it is : https://github.com/c-thun/meridio You will see two send cases in the adb logcat. I am trying to only send the message this time (regardless of the console output) and the first time, I send the name of one file as a message only while the other time I send the name of two files And the logs attached below (output_twiceAgain.txt) is the logcat output when I just directly use
And try to receive the message on the other device. I also tried this after reversing the roles to no avail |
I will try to run your repo on my phones. |
By some random method : One device did manage to send a Hey message to the other (I saw it received on the second device) but that so far has just been an anomaly. Unable to reproduce it |
Any updates? |
@C-Thun Still haven't had a chance/free time to test it... |
No worries. With Nearby Share being pushed out to all android users, my project no longer is time constrained and has become more of a enthusiast learning endeavour. Take your time. I am also between projects currently :) |
I didn't know this API was there. This sounds perfect. I'll try this out asap. Thanks a lot |
Repeatedly getting this while using sendMessage() and sendFile().
My code is as follows -
EDIT : In addition, whenever the server tries to run
createGroup()
, it always returns with the error as follows{ "code" : 2, "message": "Operation failed because the framework is busy and unable to service the request" }
The text was updated successfully, but these errors were encountered: