Skip to content
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

Error "Tunnel failed, Err #2: Device isn't connected" when multiple device added #4

Open
rajeshd50 opened this issue Nov 29, 2016 · 2 comments

Comments

@rajeshd50
Copy link

I'm using latest node-usbmux,
Ubuntu: 16.04
libimobiledevice usbmuxd installed.

When I add multiple device and create tunnel for them it's works perfectly. The issue occurs when I remove a device and reconnect again.

In the app code I'm creating tunnel for each device when the device is connected. The issue only occurs when reconnecting the phone.

Is this an issue with the library or in the way I'm creating tunnel?

Help will be appreciated. Thanks

@DeMille
Copy link
Owner

DeMille commented Dec 20, 2016

Here's how I would listen to / create tunnels for devices:

var listener = usbmux.createListener()
  .on('attached', function(udid) {
    console.log('Device attached: %s', udid);
    createSocket(udid);
  })
  .on('detached', function(udid) {
    console.log('Device detached: %s', udid);
  })
  .on('error', function(err) {
    console.log(err);
  });


function createSocket(udid) {
  usbmux.getTunnel(10022, {udid: udid}) // <-- with udid
    .then(function(tunnel) {
      console.log('Tunnel created on %s', udid);
      tunnel.write('hello');
    })
    .catch(function(err) {
      console.log(err);
    });
}

Are you doing something similar? You can enable debugging and see if something is going obviously wrong with the usbmuxd handshake. Set an environment variable export DEBUG=usbmux:* to enable that output.

There was also problem with the library and linux/libimobiledevice which could be it.

The usbmuxd that comes with libimobiledevice only gets started when a device is attached and stops as soon as the last device is removed. It's a different behavior that osx/windows where it always runs in the background. I added in a filesystem watcher to check for the usbmuxd.pid file on linux, and it seems to work ok for me, even if it is pretty hacky. You can check it out and see it solves it. If its works ok for you too I think I'll call it good and merge.

You can install the github branch with npm with
npm install DeMille/node-usbmux#ubuntu

@rajeshd50
Copy link
Author

I'm doing quite similar like that one you wrote.
Instead of watching device attach/detach with usbmux.createListener() I'm using node-usb-detection, this also returns the udid of the connected device.

After then I'm creating the tunnel as you said earlier using usbmux.getTunnel(port, {udid: udid})

What I'm doing is that,

function createSocket(device) {
     usbmux.getTunnel(10022, {udid: device.udid}).then(function(tunnel) {
         device.tunnel = tunnel;
     })
     .catch(function(err) {
         console.log(err);
     });
}

In other function I'm using device.tunnel to listen or write from the socket. Till now this is totally fine. Once I detach the device, and attach again, the same function createSocket(device) get called again, this time I'm getting this error,

Is the socket is not closing when detaching the device?

I'm gonna try with the specific branch, I'll let you know any progress. But please tell me if this approach is ok or I need to change something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants