What to use? WCF or sockets? in c # program

I need to create a C # program that will run on several of our local Windows client computers. These "client" programs will have to accept commands from the "admin" program executed on another machine. Commands may consist in rebooting client computers, returning some local information about the IP address, etc. Back to the admin program.

But how to do that? I know a little about WCF, but is this the right way? If I go with WCF, I will have to force the client programs to run the service method, like every second, to check for new commands. With sockets, I establish a β€œdirect” connection, and the client just waits for a command to receive - is this not correctly understood?

Which way would be right for me?

We are talking about ~ 10 clients, and I want to get the maximum delay (send a command - get information back) in 1 second.

Any clues would also be appreciated.

Best wishes

+4
source share
6 answers

Duplex WCF server. Basically, the clients all connect to the server (so there is only 1 server), and the server uses its duplex channel to access the clients when necessary. No polling, scales well, etc. The biggest problem that you will encounter is to set a long timeout in case you do not send anything for a while, so that the channels time out.

In the end, WCF will be a lot easier.

A few links:

http://msdn.microsoft.com/en-us/library/ms731064.aspx

and

http://www.codeproject.com/Articles/491844/A-Beginners-Guide-to-Duplex-WCF

I hope this helps.

+5
source

You can force WCF clients to act as servers and connect to them using the management and management program, which is not a problem. Go for WCF if you don't want to mess with the ugly stuff sockets can bring. WCF can be easily configured in the app.config application, and you can make it a truly self-hosted command-line application, even if you don't need an IIS server. After that, the configuration will be restored and simplified.

+1
source

You can use .NET Remoting, which can provide a push backchannel from server to client (using callbacks). It does not need a second TCP connection in the other direction, so you do not need to communicate with client firewalls and routers.

Remoting is considered obsolete, but has its place.

In any case, I would not use the WCF polling method. This results in poor latency and a DDOS situation for the server.

If you can get clients to open the port and then host the WCF service, perhaps the best idea.

+1
source

With a small number of machines and the modest performance requirements that you talked about, I think WCF will be easier than sockets.

You can watch Duplex WCF. I never used it, and the WCF gave me headaches in the past anytime I needed something unusual, but this is for the problem you are talking about.

If all the computers are on the same network, here is one alternative to the announcement, unobtrusively inspired by message queues: you can use the database table as a place where messages appear and are read by customers at their leisure. Clients could simply request it and say: get me all the messages where MessageID> LastReceivedMessageID.

The disadvantages of the latter approach are that (a) you are still polling, although your database server should be able to process it, and (b) if you ever need this outside your network, you will need a VPN or a new solution .

+1
source

I would recommend a socket implementation, as in the end it probably gives you more flexibility. You can create this from scratch yourself using the socket namespace. Alternatively, you can use the network library solution. Checkout lidgren and NetworkComms.Net .

Disclaimer: I am a developer for NetworkComms.Net.

+1
source

you can use msmq ... it couldn't be easier to implement

http://msdn.microsoft.com/en-us/library/windows/desktop/ms711472(v=vs.85).aspx

I use MSMQ for a number of similar applications. It works great.

0
source

Source: https://habr.com/ru/post/1481399/


All Articles