Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

USB communication between iPad and Mac or PC

I would like to write an iPhone/iPad app that can communicate through a USB connection with a Mac or PC program (that I would also write). Does anyone know how I could go about doing this? (I realize that I may have to jailbreak my iPad)

like image 880
cduck Avatar asked Sep 02 '11 00:09

cduck


1 Answers

Socket communication via USB (USBMux) might meet your needs. When an iPad or iPhone plug in to a Mac, there will be a device description /var/run/usbmuxd. You can create a socket and connect it to /var/run/usbmuxd and send/receive packaged data to/or from iOS device. The data should be wrapped.

Here is a brief reference from theiphonewiki http://theiphonewiki.com/wiki/index.php?title=Usbmux. What I can provide is the sample code for connect to usbmuxd.

struct sockaddr_un endpoint;
size_t size;

_usbMuxSocket = socket(PF_LOCAL, SOCK_STREAM, 0);

endpoint.sun_family = AF_LOCAL;
strncpy(endpoint.sun_path, "/var/run/usbmuxd", 17);
size = (offsetof (struct sockaddr_un, sun_path)
        + strlen (endpoint.sun_path) + 1);

connect(_usbMuxSocket, (struct sockaddr *) &endpoint, size);

After that you have to "connect" to the port your App listen on iPad. The "connect" process discussed in the wiki page list above in section Sequence of Events. After the preparing work done, you can use the socket to send and read data.

like image 162
Linden Liu Avatar answered Oct 16 '22 16:10

Linden Liu