WCF VS. Sockets

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

Here are some parts of the game:

- communication with the client / server for playback on the Internet

-peer to connect to the local network.

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

The game does not require a high communication frequency (3-4 per second is enough).

+6
c # sockets wcf
source share
4 answers

The purpose of WCF is to keep developers writing code for different transport protocols, and it has a large number of functions, which is why it is slower than Sockets. Plus WCF is designed for service oriented applications. I do not think that Games fall into this category.

But since you specify only 3-4 queries per second, WCF may be the best option, as it is very flexible and will save a lot of development time.

Some moments:

Links that start with net * are for use between .NET applications. (Both client and WCF server)
If any of them is not WCF: you can use bindings that do not start with a network prefix. BasicHttpBinding, WSHttpBinding, etc. They are much slower than network bindings since there is a lot of overhead.

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

Here are some useful links for P2P:

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

+6
source share

If you want to maximize performance, then sockets are the way to go, WCF has both data and processing costs. But ... if performance is important to you, you should also consider assembler instead of C #.

WCF will process 3-4 requests per second without blinking.

I would start with WCF, it will save you a lot of development time, you do not need to roll your own parser, etc. Instead, you can focus on other parts of the game. If this actually turns our WCF too slow for your game, you can throw away the WCF and go instead of sockets.

+10
source share

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

In your case, you can also look at messaging technologies such as MSMQ , ZeroMQ or ActiveMQ , which provide excellent abstraction over sockets and greatly simplify development.

+2
source share

If you don't need real-time performance (you use C #, so I assume this is the case), then I would suggest WCF.

WCF will provide you with much simpler OOP style tools for writing your Server-Client protocol.
The advantage of WCF is that in the end, the protocols and code that you ultimately write in it is much easier to maintain and follow.

It will be easier to add and change functions in the protocol if you ever want to add something.

WCF is very customizable, so you better read about the different methods of transferring the data it provides and how to overload them.

You can use different types of bindings to optimize data transfer:

WCF deep linking

+1
source share

All Articles