tradle / react-native-udp

node's dgram for react-native
MIT License
341 stars 154 forks source link

[iOS] Error when rebinding sockets & listening on message #210

Closed BILLXZY1215 closed 2 years ago

BILLXZY1215 commented 2 years ago

Description

Hi, I'm trying to rebind two used sockets, it works fine in android, but not in iOS.

Steps to reproduce

const app = dgram.createSocket({type: 'udp4', reuseAddr: true});
const server = dgram.createSocket({type: 'udp4', reuseAddr: true});

//First Bind, everything is ok
app.bind(app_port, err => {
          if (err) {
            throw err;
          }
          console.log('app bound to port', app_port);
        });
server.bind(server_port, err => {
          if (err) {
            throw err;
          }
          console.log('server bound to port', server_port);
        });

// Send Data
app.send(open_msg, 0, open_msg.length, server_port, URL, function (err) {
      if (err) {
        throw err;
      }
      console.log('app sent data, starting frame');
    });
app.on('message', async (data, rinfo) => {
    // Some Tasks
})

// On sometime: rebind
 app.bind(app_port, err => {
        if (err) {
          throw err;
        }
        console.log('app bound to port', app_port);
      });
server.bind(server_port, err => {
        if (err) {
          throw err;
        }
        console.log('server bound to port', server_port);
      });

// And then send another msg
 app.send(
        close_msg,
        0,
        close_msg.length,
        server_port,
        URL,
        function (err) {
          if (err) {
            console.warn(err);
            throw err;
          }
          console.log('app sent data, closing frame');
        },
      );

Current behavior (console log when rebinding)

This is how it behaves in iOS:

Screen Shot 2022-04-21 at 10 04 24 PM

Expected behavior

This is how it behaves in Android (normal):

Screen Shot 2022-04-21 at 7 22 33 PM

About sending data frames

The codes shown above have this segment:

app.on('message', ...

It works fine in android, however, in iOS I did not receive any listened callbacks, it seems this listening function is not working...

Any workaround? Thanks.

github-actions[bot] commented 2 years ago

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.