10

I would like to know which of WCF or .NET Sockets is the more efficient and the more recommended in a game developpment scenario.

Here are the different parts of the game :

-a client/server communication to play on the internet

-peer to peer on local network.

I would like to know which technology you would use on these parts (wcf on both, socket on both, wcf on one and socket on the other...) and why, if possible.

The game involved doesn't require a high communication frequency (3-4 per second is enough).

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
kite
  • 679
  • 2
  • 8
  • 19

4 Answers4

11

If you want to maximize performance sockets is the way to go, WCF has both data and processing overhead. But... if performance is that critical to you, you should also consider assembler instead of c#.

WCF will handle 3-4 requests per second without a blink.

I would start with WCF, it will save you a lot of development time, no need to roll your own parser etc. You can concentrate on other parts on the game instead. If it actually turns our that WCF is too slow for your game you can throw WCF out and go for sockets instead.

Albin Sunnanbo
  • 46,430
  • 8
  • 69
  • 108
7

The purpose of WCF is to save developers writing code for different transport protocols and it has large number of features so thats why it is slower than Sockets. Plus WCF is for service oriented applications. I dont think Games fall into this category.

But as you mention only 3-4 requests per second, WCF might be a better option as its very flexible and will save a lot of development time.

Some points:

The bindings that start with net* are meant to be used between .NET applications. (Both client and server WCF)
If any of the one is not WCF: You can only use the bindings that does not start with a net prefix. BasicHttpBinding, WSHttpBinding etc. These are much slower than the net* bindings as lot of overhead is there.

You can go ahead with NetPeerTcpBinding and play with it for a while. It also supports duplex communication.

Here are some useful links for P2P:

Peer-to-Peer Programming with WCF and .NET Framework 3.5
http://blogs.interknowlogy.com/2009/08/05/building-a-really-simple-wcf-p2p-application

A G
  • 21,087
  • 11
  • 87
  • 112
3

Both technology can manage the number of requests per second that you are mentionning, however the programming model is quite different. Sockets are very low level and require that you build your own communication protocol on top of it. However, the overhead can be minimal. WCF is modelled after RPC (Remote Procedure Calls) and provides an abstraction on the transport. It allows you to use the same API with very different technologies such as web services or messaging. However, the abstraction provided has its own set of problems such as a certain complexity or steep learning curve...

In your case, you could also look at messaging technologies such as MSMQ, ZeroMQ or ActiveMQ that provide a nice abstraction over sockets and simplify the development a lot.

Julien
  • 7,821
  • 3
  • 23
  • 16
1

If you don't need real-time performance (You're using C# so i guess that's the case) then I'd suggest WCF.

WCF will give you a much easier OOP style tools to write your Server-Client protocol.
The advantage with WCF is that in the long run the protocols and code you eventually write in it is much easier to maintain and follow.

It'll be easier to add and change features to the protocol if you ever want to add anything.

WCF is highly customizable so you better read about the different data-sending methods it provides, and the ways to overload them.

You can use different binding types to optimize your data transfer:

WCF Binding In Depth

Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185
  • 1
    C# can be used to write real time applications (I suppose it also depends what you mean by real time though). – dodgy_coder Jun 12 '12 at 01:16
  • @yochai TImmer I want a communication between WMS and WCS which would be real time like 250 ms. which one will be preferable WCF or Socket – Dutt93 Jul 01 '18 at 14:11
  • @Dutt93 I would pick WCF. the latency is lower than 1 ms if configured right (Test on a local machine, the rest is Netowrking overhead. The networking overhead is there no matter what implementation you use.). – Yochai Timmer Jul 01 '18 at 14:34
  • @YochaiTimmer Thanks for your quick response. Yes, It make sense. Can you please tell me some real benifits of WCF over Socket, because where ever i found people are saying Socket is better than WCF. – Dutt93 Jul 01 '18 at 14:44
  • @Dutt93 Scaling and maintainability. If you are planning a large project where you may have multiple layers and configurations, you would probably use WCF. You don't need to reinvent the wheel for every bit you want to send over the network. WCF gives you a nice layer of abstraction. Sockets are arguably more efficient than WCF. But only if written correctly, and then you have years of debugging for reinventing your communication layer. Also pure Assembly and C would be more efficient than C# if efficiency is what you're after. – Yochai Timmer Jul 01 '18 at 14:52