开发者

USB communication between iPad and Mac or PC

开发者 https://www.devze.com 2023-04-01 05:22 出处:网络
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 thi

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)


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.


Does it have to be a USB connection?

If not, then Robbie Hanson's GCDAsyncSocket is great for connecting all kinds of Apple devices. I used it last year to connect a bunch of iPads to a single app running on a Mac mini.

0

精彩评论

暂无评论...
验证码 换一张
取 消