I wish to develop a client-server application in .NET that functions as follows:
I'm just wondering if I can use WCF for this purpose, or should I go with good old sockets. Although the initial network would be small, I want it to scale (1000s of clients). Any suggestion would be greatly appreciated.
The raw socket interface provides direct access to lower layer protocols, such as the Internet Protocol (IP) and Internet Control Message Protocol (ICMP or ICMPv6). You can use raw sockets to test new protocol implementations.
A raw socket is used to receive raw packets. This means packets received at the Ethernet layer will directly pass to the raw socket. Stating it precisely, a raw socket bypasses the normal TCP/IP processing and sends the packets to the specific user application (see Figure 1).
A raw socket is a type of socket that allows access to the underlying transport provider. This topic focuses only on raw sockets and the IPv4 and IPv6 protocols. This is because most other protocols with the exception of ATM do not support raw sockets.
Today I would never go down to such a low level as sockets unless you really have to. Working with high level abstractions is way more productive and creative. Better spend 2-3 days of learning WCF or .Net Remoting then 2 weeks of debugging low level socket stuff.
We had a similiar decision to do a few weeks ago. We decided to use Remoting, since you can work on object level, its damn simple to set up and quite efficient. We could have used WCF, but it was not that simple to set up.
The big advantage of Remoting or WCF is that you can pass objects between server and client and call methods on them on each side.
Suppose you have written an abstraction for your camera like:
class Camera
{
public CompressedImage GetFrame()
{
....
return image;
}
}
Then you can create a remote object on the server and write something like:
var cam = SomeClientObject.GetCamera(); //get proxy object for the cam
....
var frame = cam.GetFrame();
which will call the method GetFrame() on the client and pass you the image over the (inter-) net, if the image is serializable. The only thing you have to keep in mind is, which objects create a proxy on the other side, and which objects are copied to the other side.
Thats really powerful and woks for us like a charm. So free your mind from sockets :)
I've just been doing the exact same thing. I wrote a TCP-based server that can handle 1,000 simultaneous client connections with ease in about an hour and culminating in 80 lines of code. I have spent days trying and failing to get a duplex WCF server to do the same thing. It took 175 lines of code to get a duplex WCF server and client working at all and it crashes if 30 clients try to connect simultaneously.
So I must disagree with the other answers here: I have found WCF to be an absolute disaster and raw sockets to be much easier and more reliable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With