Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Relation between UDPClient and Socket

in what kind of a relation are Socket and UdpClient classes in C#?

Could the relation be described by a one of the design patterns?

like image 866
Rok Povsic Avatar asked Jul 07 '11 09:07

Rok Povsic


2 Answers

UdpClient is a wrapper around a socket using UDProtocol. It's similar to the TCPClient, all it does is provide yet another layer of abstraction to make network programming that much easier.

Update:

Also, I never really understood why some people prefer UDPClient and TCPClient over using the base socket class. It can give you an ample start to learn network programming in .NET without too much pain, but I feel the more layers of abstraction you have that the less you will understanding of what is going on under-the-hood. I feel that this makes it much harder in the long run to debug complex or weird behaviorial problems in your code because so much of what is going on is hidden from you, because you are several layers high in abstraction. Even the .NET Socket class is a layer of abstraction as its a wrapper around a native (Berkeley Sockets Interface) socket, and I never really felt that network programming in native C++, for example, was that difficult either.

Though, if you follow standards, guidelines and write high quality code you may not have any problems at all (minus environmental and circumstantial problems), but I always recommend learning the base Socket class so you have a better understanding of .NET networking. I guess it all depends on how deep you are interested in learning the framework and becoming an expert on the subject.

In short conclusion, either way is generally okay based on your requirements and necessity, but I always recommend learning over abstraction any day.

like image 92
David Anderson Avatar answered Nov 02 '22 08:11

David Anderson


Based on danderson's response, it sounds a little like the Facade pattern.

A facade can: make a software library easier to use, understand and test, since the facade has convenient methods for common tasks;

like image 21
Peter K. Avatar answered Nov 02 '22 10:11

Peter K.