I have a C API that talks to hardware and I want to ultimately make calls to that API from a browser. Thinking some to the c++ servlet lib’s are too complicated, as is JNI, I thought I could prove the concept like this:
A java servlet gets a simple string message via HTTP.
The servlet opens a socket to pass along data via UDP.
C process running opens a socket and awaits message.
C process receives message, makes call, and send back simple string message via UDP.
Servlet passes responce message back to browser.
In short, can a servlet open a socket to talk to native (winsock) code?
Yes this would be a great solution.
However one thing you need to consider carefully is how concurrent requests need to be handled when 2 servlets make a connection. If the library/machine it might be useful to use a simple socket which does not accept other connections once a connection is made.
In the java you can then serialize access to the librarysocket, using a BlockingQueue for example, so that you have a nicely defined concurrent access behavior.
This will avoid spurius unrepeatable problems.