开发者

C# - Relation between UDPClient and Socket

in what kind of a relation are 开发者_C百科Socket and UdpClient classes in C#?

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


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.


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;


UdpClient is just a convenience class which makes it easier to work with Sockets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜