tags:

views:

832

answers:

5

Is it possible to have two applications on the same computer to talk to each other directly over USB (no cable, no associated devices)? Is it easy/hard? What API would you guys recommend?

Yes, I posted a similar thread, but it was asking specifically for a JAVA/USB implementation, which I found, but I need windows support. So now I'm looking for any USB API - it doesn't have to work in java. I can always just use JNI/JNative to use the native code/library.

I haven't found many people on the internet that have done the same thing.

+3  A: 

If you are just looking to allow two processes to communicate, you could use Unix or Domain sockets. I can't think of a situation where interprocess communication over USB locally would be an advantage. Java has very good support for doing this.

Arcane
Yes, that was my first thought too. Unfortunately, this is more of a prototype/proof of concept, and I'm not sure of the reasoning behind using USB.
jbu
I suppose you could create a device driver for a "NULL" USB device that followed the USB serial spec and just echoed input to output but showed up in the USB enumeration. Then, you could connect to this virtual device and use it. Seems like a lot of effort, though.
Arcane
This is what I'm starting to believe is the solution. And it seems like you're right, from all the articles I've read, USB is a very very complicated protocol operating over many layers. Sigh......WHY CANT WE JUST USE TCP/IP?!
jbu
+2  A: 

No Cable and/or no Devices

So what you are asking then is not possible (or even make any sense) it would be like asking how can 2 apps talk via serial ports with nothing connected..

Perhaps you could try and find out what the actual end aim is, if its just interprocess communication ther are many different ways to skin that cat...(com, wcf, memory mapped files etc etc)

Tim Jarvis
Yes, interprocess communication. You ought to be able to listen on a bus using a driver, right? You should also be able to use a driver to send signals over a bus, right? Shouldn't you then be able to send/receive signals over the bus using drivers and no device? What am I missing?
jbu
When I say drivers, I mean the USB driver, not a driver for a peripheral.
jbu
A: 

Communications over USB necessarily involves electrical connections and pull-up resistors and particular voltages appearing on particular lines at particular times. These are all pretty hard to simulate without an actual cable.

Jan Axelson's USB Central is a great place to start to learn about USB communications.

Greg Hewgill
+5  A: 

The USB "Bus" is the wire. USB is NOT for interprocess or even peer-to-peer communications. It is solely for communication between a host and a peripheral over a cable where the host initiates any/all traffic. You cannot (normally) connect 2 hosts together, nor two devices together, or have any sort of symmetrical communication between a host/device.

If you ONLY want inter-process communication between two process on the same machine, USB is NOT the way to go. It is completely non-sensical. If you want inter-process communication between two process on two different machines, you should use TCP/IP.

If you are to developing a USB device and want to develop the host and device software before any prototype hardware is ready, and what you are REALLY after is some development or simulation environment where you can do that on the same machine, hook them up, and test it, that is an entirely different thing.

robottobor
Thank you for your response. What if I did want to connect a 2 hosts together using a male-to-male cable. Do you know what that would entail? What are typical abnormal cases that people would connect 2 hosts together?
jbu
You can't connect 2 hosts together and have it work. The hardware does the negotiation and will either ignore it or put both ports into an error state.
pjc50
A: 

I guess with a lot of kernel work you might get something like this to work. There is an existing product that can transfer usb other network. So i guess it simulate usb host controller or something similar. If you can simulate host controller you can simulate actual device connected to this controller. And let the user mode application to control this device.
But i would estimate it as an at least 6 MM project for experienced kernel programmer with deep understanding of USB protocol in additional.
And the main question is why ? I can't find any logical reason for this use case (does not mean that it's not exists).

Ilya