SH,
I have not done the socket route but I have created something like this
using .NET Remoting. What you'll need is to create an assembly in which you
have defined an interface. In this interface you'll have a method that takes
a parameter, perhaps the command that the user passes.
Create the remoting server. Create a class in this remoting server that
inherits from MarshalByRefObject and implements the interface you defined in
the other assembly. When you start up your service, create the TcpChannel or
HttpChannel (whichever you want, Tcp is faster) with an appropriate port and
register the channel using ChannelServices.RegisterChannel and then
RegisterWellKnownServiceType using RemotingConfiguration using the class
that you created in your service application that implements your interface.
In the client, reference the assembly that contains your interface with the
method call and get an object of that type using Activator.GetObject setting
up the ip address and port to be used. Once you have the object, call the
method passing in the command and get its returned data. That's pretty much
it. You should be able to find ample examples of this using Google also.
HTH
Steve
"SH" <sh*****@prupipe.com> wrote in message
news:De*****************@newsread3.news.pas.earthl ink.net...
Thanks, Chris. I don't know how to do any of this. Can you point me to
any articles, code, etc about creating sockets and using them.
Chris wrote: SH wrote:
I wish to create a program (really a Windows Service) that sits and
waits for a client PC to communicate with it, but I can't come up with
a good method of doing so.
I want to have a service running on a server, waiting for clients to
send it commands. The service would then do something based on the
command and send the information back to the client. This is exactly
what any database does. What is the best method for doing this?
The only method I can come up with, is that when the client wishes to
communicate with the service it would write a file on the server. The
service would check for the existence of that file every X number of
seconds. Then the service would do it's thing and write back another
file with the results. The client would constantly check every X
number of seconds for the existence of the results file and then read
the file.
I, of course, don't like this solution. It's not elegant, it avoids
the whole point, and I can see timing problems throughout.
Is there another way for a service to just "listen" for a stream of
data directly without a file intermediary? What command just
"listens"? And how do you receive a stream of data out of thin air?
Thanks for any ideas.
You can create a socket that listens on a specific port (in a windows
service). When that socket is connected to you can do whateever you
want on the server. You can do this through remoting as well.
Chris