Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interprocess communication 2

Status
Not open for further replies.

scorpio66

Programmer
Jun 27, 2001
229
GB
Hi

I've got an application which runs as a service using the NTSVC component.

I need to write a control application which can communicate with the service, to do thinks like get status information, change configuration parameters, etc.

What is the best way to handle this communication?

Thanks in advance,

Chaz
 
The way I have done this is by using the registry (or you could use an INI file). If the services configuration & parameter information is all held in the registry, your control application can modify it, then the service could pick it up on the fly or when it is restarted.

Madlarry
 
While I can do that, it means that the server needs to poll for registry changes. Not a big deal, admittedly.

However, That doesn't allow the client to request information from the server. Also, it means that the client has to run on the same box as the server (which may be a restriction that I have to accept.)
 
You can do it with COM/DCOM...

Basically, you need to wrap your configuration and status stuff into a publicnotcreatable class. And then you need a multiuse connector class. Bung both of these into an ActiveX Exe project.

Your clients (and from this point of view the service is a client as well) get a reference to a Connector object, which in turn always returns a refernce to the SAME config/status object. And Bob's your uncle.

For those that can be bothered to read any further, I include a trivial example.

1) Following code is for the ActiveX exe project, which I happen to have called StatusTest:

Class Status (quickly built using class wizard)
-----------------------------------------------

[tt]Option Explicit

'local variable(s) to hold property value(s)
Private mvarStatusName As String 'local copy
Private mvarStatusActive As Boolean 'local copy
Public Property Let StatusActive(ByVal vData As Boolean)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.StatusActive = 5
mvarStatusActive = vData
End Property

Public Property Get StatusActive() As Boolean
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.StatusActive
StatusActive = mvarStatusActive
End Property

Public Property Let StatusName(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.StatusName = 5
mvarStatusName = vData
End Property


Public Property Get StatusName() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.StatusName
StatusName = mvarStatusName
End Property[/tt]


Class Connector
---------------

[tt]Option Explicit

Public Property Get Status() As Status
Set Status = gStatus
End Property

Private Sub Class_Initialize()
If gStatus Is Nothing Then
Set gStatus = New Status
End If
glngUseCount = glngUseCount + 1
End Sub

Private Sub Class_Terminate()
glngUseCount = glngUseCount - 1
If glngUseCount = 0 Then
Set gStatus = Nothing
End If
End Sub[/tt]


Global Module
-------------

[tt]Option Explicit
Public gStatus As Status
Public glngUseCount As Long[/tt]


Now, in your clients you just need something like:

[tt]Dim Connector As Object
Dim Status As Object

Set Connector = CreateObject("Statustest.Connector")
Set Status = Connector.Status[/tt]

 
I guess I should also say, before anyone points out lack of error checking etc, that this is just illustrative of a general approach.

it has the added bonus that you could make the 'Status' object persistable...
 
Thanks - I've adopted a much more complicated approach using TCP/IP, which is a tech that I at least understand and can predict ...

I'm in two minds now - do I recode everything to use COM/DCOM or do I carry on with my socket code ...

Dilemma, dilemma ... :)

Chaz
 
Knowing you, I'm surprised you didn't go for an XML/SOAP solution...

Mike
 
lol - never thought of that - darn, a third option ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top