-
Notifications
You must be signed in to change notification settings - Fork 155
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
setBroadcast(true) hangs on Android #82
Comments
It seems we must not call `setBroadcast()` after receiving thread was started. At least on my setup (Android emulator or Samsung Galaxy S8 running on Android API 28) this will result in deadlock. Therefore I removed automatic start of receive on bind and introduced new method `startReveiving()`. It can be called like this: ``` let udpClient = dgram.createSocket('udp4') this.udpClient.on('bound', () => { this.udpClient.setBroadcast(true) this.udpClient.startReceiving() }) udpClient.bind() ``` See issue: tradle#82
Hi, I got the same issue but in a different way. I just changed logInfo(`Sending ${msg.messageType} to Broadcast ID: ${msg.id}`);
var socket = dgram.createSocket("udp4");
logInfo(`Created ${msg.messageType} to Broadcast ID: ${msg.id}`);
const data = toByteArray(JSON.stringify(msg, replacer));
socket.bind(randomPort(), undefined, (err) => {
logInfo(`Binded ${msg.messageType} to Broadcast ID: ${msg.id}`);
if (err) {
logWarning(err);
reject(err);
return;
}
if (Platform.OS === "ios")
socket.setBroadcast(true);
getNetworkInfo().then(ni => {
const br = getBroadcastAddress(ni!.details.ipAddress!, ni!.details.subnet!);
try {
setTimeout(() => {
socket.close(() => {
logInfo("Closing with Timeout " + msg.messageType + " from broadcast ID: " + msg.id);
reject(err);
});
}, 3000);
socket.send(data, 0, data.length, GUZZLO_PORT, br, err => {
// Android freezes here
logInfo(`Sent ${msg.messageType} to Broadcast ID: ${msg.id}`); [Wed May 20 2020 20:20:33.629] INFO Lenovo T : Sending HANDSHAKE to Broadcast ID: 1589995234191
[Wed May 20 2020 20:20:33.639] INFO Lenovo T : Created HANDSHAKE to Broadcast ID: 1589995234191
[Wed May 20 2020 20:20:33.644] INFO Lenovo T : Binded HANDSHAKE to Broadcast ID: 1589995234191
[Wed May 20 2020 20:20:33.655] INFO Lenovo T : Sent HANDSHAKE to Broadcast ID: 1589995234191
[Wed May 20 2020 20:20:33.665] INFO Lenovo T : Closing HANDSHAKE from broadcast ID: 1589995234191
[Wed May 20 2020 20:20:33.672] INFO Lenovo T : Scan complete 1 node found
[Wed May 20 2020 20:20:33.747] INFO iPad Air : Received HANDSHAKE from 192.168.1.41:29663 ID: 1589995234191
[Wed May 20 2020 20:20:33.756] INFO iPad Air : Sending HANDSHAKEBACK to 192.168.1.41:12001 ID: 1589995233755
[Wed May 20 2020 20:20:33.775] INFO Lenovo T : Received HANDSHAKEBACK from 192.168.1.43:55821 ID: 1589995233755
[Wed May 20 2020 20:20:36.673] INFO Lenovo T : Closing with Timeout HANDSHAKE from broadcast ID: 1589995234191
[Wed May 20 2020 20:20:45.190] INFO iPad Air : Sending HANDSHAKE to Broadcast ID: 1589995245018
[Wed May 20 2020 20:20:45.200] INFO iPad Air : Created HANDSHAKE to Broadcast ID: 1589995245018
[Wed May 20 2020 20:20:45.200] INFO iPad Air : Binded HANDSHAKE to Broadcast ID: 1589995245018
[Wed May 20 2020 20:20:45.210] INFO iPad Air : Sent HANDSHAKE to Broadcast ID: 1589995245018
[Wed May 20 2020 20:20:45.230] INFO iPad Air : Closing HANDSHAKE from broadcast ID: 1589995245018
[Wed May 20 2020 20:20:45.230] INFO iPad Air : Scan complete 1 node found
[Wed May 20 2020 20:20:45.141] INFO Lenovo T : Received HANDSHAKE from 192.168.1.43:56298 ID: 1589995245018
[Wed May 20 2020 20:20:45.433] INFO Lenovo T : Sending HANDSHAKEBACK to 192.168.1.43:12001 ID: 1589995246008
[Wed May 20 2020 20:20:45.450] INFO iPad Air : Received HANDSHAKEBACK from 192.168.1.41:58361 ID: 1589995246008
[Wed May 20 2020 20:20:48.200] INFO iPad Air : Closing with Timeout HANDSHAKE from broadcast ID: 1589995245018
[Wed May 20 2020 20:20:53.651] INFO Lenovo T : Sending HANDSHAKE to Broadcast ID: 1589995254197
[Wed May 20 2020 20:20:53.654] INFO Lenovo T : Created HANDSHAKE to Broadcast ID: 1589995254197
[Wed May 20 2020 20:20:53.667] INFO Lenovo T : Binded HANDSHAKE to Broadcast ID: 1589995254197 |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community attention? This issue may be closed if no further activity occurs. |
Hi @serayuzgur |
Hi @shynst @serayuzgur - did you find a solution? |
@nishmeht7: I did fix it 2 years ago (works very well in production code): It seems we must not call See details in my commit above. |
@shynst Thank you so much, you're a life saver! |
Hi shynst, npx react-native run-android --mode release --deviceId R9TWA08193A npx react-native run-android --deviceId R9TWA08193A I am really stumped because on Release mode you don't see any logs on what is happening. |
In order to send broadcast messages we need to call
setBroadcast()
first.However this method hangs and never returns!
I tested in Android emulator and with a Samsung Galaxy S8. Both running on Android API 28.
Any ideas what is going on here?
The text was updated successfully, but these errors were encountered: