Sunday, June 27, 2010

Socket programming vs. WCF [Ashish Khandelwal]

By Ashish Khandelwal, July 29, 2009

A very simple scenario where client sends a request to server to perform certain action. There is no much data transfer between two parties – Probably no more than 50 bytes. We need to decide whether we go with Socket programming or use WCF (request-reply messaging pattern).
The analysis says:A socket is an address which combination of an IP address and a port into a single identity, much like one end of a telephone connection is between a phone number and a particular extension line at that location. When an application creates a socket, the operating system forwards incoming IP packets to the corresponding application or service process by extracting the socket address information from the IP.
Therefore, in the base of WCF there is socket programming. But with WCF lots of work is already done for you. E.g. with WCF you'll get plumbing and serialization and such. The Protocol is already figured out for you: request/response message passing. The lowest level transport details are already implemented for you. The security features are coded. You just need to choose and configure.
With socket programming you will require much more work and testing, but can potentially be faster. You'll have to create your own protocol, decide how messages are serialized and so forth. Basically if you transport byte[] data then Socket programming is best because you will not be required to serialize you data on both side.
I will say that WCF is kind of collection of APIs give to us over the socket programming with various options and feature. We just need to choose the suitable option.

No comments:

Post a Comment