Hi,
I have a Windows .NET client process that I'm developing that's going to
need to communicate with some C code running on a Red Hat linux box.
The client will send a text request and receive a text response after
some database processing has been carried out, the calls will need to be
synchronous.
What options do I have? I can think of a few:
Raw Sockets
CGI in a webserver
SOAP / REST calls
Some sort of RPC generator / library?
what others?
What works well and has good library support to save me reinventing the
wheel?
Cheers,
Matt
|
|
0
|
|
|
|
Reply
|
mcharles48 (4)
|
5/20/2011 7:21:52 AM |
|
On Fri, 20 May 2011 08:21:52 +0100, Matt Charles
<mcharles48@gmail.com> wrote:
>Hi,
>
>I have a Windows .NET client process that I'm developing that's going to
>need to communicate with some C code running on a Red Hat linux box.
>The client will send a text request and receive a text response after
>some database processing has been carried out, the calls will need to be
>synchronous.
>
>What options do I have? I can think of a few:
>
>Raw Sockets
>CGI in a webserver
>SOAP / REST calls
>Some sort of RPC generator / library?
>what others?
>
>What works well and has good library support to save me reinventing the
>wheel?
There are probably 1000s of ways of doing this and I'm not going to
name them all ;-)
A lot depends on who is going to maintain this software and what
technology they are happy with. There's no "best" way IMHO.
If the communication protocol is very simple then I would use TCP/IP
sockets, but then I have already developed loads of similar code.
Failing that you could use SOAP since there are a large number of SOAP
frameworks available.
--
(\__/) M.
(='.'=) Due to the amount of spam posted via googlegroups and
(")_(") their inaction to the problem. I am blocking some articles
posted from there. If you wish your postings to be seen by
everyone you will need use a different method of posting.
|
|
0
|
|
|
|
Reply
|
i1658 (113)
|
5/20/2011 9:38:17 AM
|
|
Matt Charles <mcharles48@gmail.com> writes:
[...]
> What options do I have? I can think of a few:
>
> Raw Sockets
> CGI in a webserver
> SOAP / REST calls
> Some sort of RPC generator / library?
> what others?
>
>
> What works well and has good library support to save me reinventing
> the wheel?
Rest assured that the probability that anything you can ever come up
during your whole lifetime (or that anything someone came up during
the about sixty years stored program computers have existed) while
remain in use for a few thousand years without a basic design change
is low enough to be considered equivalent to zero for all practical
purposes.
|
|
0
|
|
|
|
Reply
|
rweikusat (2680)
|
5/20/2011 2:00:58 PM
|
|
Matt Charles <mcharles48@gmail.com> wrote:
> Hi,
> I have a Windows .NET client process that I'm developing that's going to
> need to communicate with some C code running on a Red Hat linux box.
> The client will send a text request and receive a text response after
> some database processing has been carried out, the calls will need to be
> synchronous.
Synchronous where? Regarding the .NET client or the C "code" on the server?
Synchronous how? Are you talking basic I/O or sychronous in regards to some
overall transactional flow?
Windows and .NET frameworks tend to dictate the use of threads for
concurrency (even "asynchronous" calls are just put onto another thread).
This means that all the different modes of communications are more alike
than not, in terms of low-level I/O implementation details.
Not so in C. In C it's as just common to use threads as non-blocking I/O.
There may be callbacks or the implementation may use a resumable state
machine which falls back to the caller. And mixing and matching methods is
more of a hassle than in .NET, where if a library uses a callback or
delegate you can just block and synchronize on a semaphore triggered by the
callback, or otherwise coax the behavior of the library to suit the
application's overall design.
Point being, what will dictate your choice of methods is probably what is
most convenient for the C, server-side of this equation. Is the server code
using its own event loop, something like libevent, or is it just
multithreaded? Are there ready-made solutions that are easily pluggable into
the overall design of the C code?
> What options do I have? I can think of a few:
> Raw Sockets
> CGI in a webserver
> SOAP / REST calls
> Some sort of RPC generator / library?
> what others?
> What works well and has good library support to save me reinventing the
> wheel?
Good library support for the C code? Again, it all depends. freshmeat.net is
a solid place to start looking for a solution.
|
|
0
|
|
|
|
Reply
|
William
|
5/20/2011 8:19:26 PM
|
|
Thanks for the input so far, but I'll try and explain more clearly. :-)
I have an existing Red Hat Linux C function (complex business logic
that contains some database access), it takes some strings as input
parameters and returns a string result. This function is currently in
a batch program and works fine.
However I now also want to call this function somehow from a new Windows
..NET GUI application. The user will press a button, get an hour glass
and wait for the response to come back (this is what I mean by
synchronous). However there may be multiple users on different PC
pressing the button at the same time, so the solution will have to cope
with that.
So I'm going to need to repackage my C code in some way to make this happen.
One possible solution: Package the batch program up as a CGI executable
and call it from Apache. The .NET code will build a URL with
parameters and submit it to the apache webserver. The server runs the
CGI program, which extracts the parameters from the QUERY_STRING
environment variable that Apache creates and then calls the C function
and outputs the result as HTML to stdout. The .NET client can then
interpret this to get the result. I'm sure this will work but the
approach seems a little "dated".
Are there any "better" solutions that anybody can think of.
|
|
0
|
|
|
|
Reply
|
mcharles48 (4)
|
5/21/2011 8:25:27 AM
|
|
On 05/21/11 08:25 PM, Matt Charles wrote:
> Thanks for the input so far, but I'll try and explain more clearly. :-)
>
> I have an existing Red Hat Linux C function (complex business logic
> that contains some database access), it takes some strings as input
> parameters and returns a string result. This function is currently in
> a batch program and works fine.
>
> However I now also want to call this function somehow from a new Windows
> ..NET GUI application. The user will press a button, get an hour glass
> and wait for the response to come back (this is what I mean by
> synchronous). However there may be multiple users on different PC
> pressing the button at the same time, so the solution will have to cope
> with that.
>
> So I'm going to need to repackage my C code in some way to make this happen.
>
> One possible solution: Package the batch program up as a CGI executable
> and call it from Apache. The .NET code will build a URL with
> parameters and submit it to the apache webserver. The server runs the
> CGI program, which extracts the parameters from the QUERY_STRING
> environment variable that Apache creates and then calls the C function
> and outputs the result as HTML to stdout. The .NET client can then
> interpret this to get the result. I'm sure this will work but the
> approach seems a little "dated".
So is the wheel, but we still use them.
Most "web service" layers (including windows beloved SOAP) are just
fancy wrappers around what you describe. Sure you could be more
"modern" and use SOAP, but why bother?
--
Ian Collins
|
|
0
|
|
|
|
Reply
|
ian-news (9882)
|
5/21/2011 8:34:39 AM
|
|
Matt Charles <mcharles48@gmail.com> writes:
> I have an existing Red Hat Linux C function (complex business logic
> that contains some database access), it takes some strings as input
> parameters and returns a string result. This function is currently
> in a batch program and works fine.
>
> However I now also want to call this function somehow from a new
> Windows .NET GUI application. The user will press a button, get an
> hour glass and wait for the response to come back (this is what I
> mean by synchronous). However there may be multiple users on
> different PC pressing the button at the same time, so the solution
> will have to cope with that.
>
> So I'm going to need to repackage my C code in some way to make this happen.
>
> One possible solution: Package the batch program up as a CGI
> executable and call it from Apache.
[...]
> I'm sure this will work but the approach seems a little "dated".
>
> Are there any "better" solutions that anybody can think of.
Provided you don't need authentication, a much simpler and even more
'dated' alternative exists: Create something which reads the input
parameters from its standard input and writes the result to its
standard output and make this accessible on some TCP port via inetd.
|
|
0
|
|
|
|
Reply
|
rweikusat (2680)
|
5/22/2011 8:26:07 PM
|
|
>
> One possible solution: Package the batch program up as a CGI executable
> and call it from Apache. The .NET code will build a URL with parameters
> and submit it to the apache webserver. The server runs the CGI program,
> which extracts the parameters from the QUERY_STRING environment variable
> that Apache creates and then calls the C function and outputs the result
> as HTML to stdout. The .NET client can then interpret this to get the
> result. I'm sure this will work but the approach seems a little "dated".
>
I just tried my simple CGI approach. The .NET client code is very easy:
Dim webClient As System.Net.WebClient = New System.Net.WebClient()
Dim result As String =
webClient.DownloadString("http://hostname.com/webservices/mc/dbtest.cgi?param1=test")
This request takes 0.12 seconds and that includes the network traffic
time, connecting to the database, performing a query and returning the
results.
So I'm very happy with that. Most of the time is taken up with creating
the database connection, I might look into using FastCGI and
maintaining a persistent database connection to make things even more
efficient.
|
|
0
|
|
|
|
Reply
|
mcharles48 (4)
|
5/23/2011 11:19:53 AM
|
|
|
7 Replies
42 Views
(page loaded in 0.16 seconds)
|