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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.