C# socket programming: part 1 of 3: page 1 of 6



Top 20 Resources


Network programming can be tough and complicated. If you are reading this because you are trying to decide on a communication mechanism for your new project then let me save you some reading. Stick with something else if you can.

Web Services gives you operating system and limited language independence and can be done over a range of transport. I have shown in another article how to use a Win Form as a web service client. .NET and Java have great web services support or you can fashion something in C++ using Xerces or other mechanisms easily enough. .NET remoting is a good choice if it is all .NET. If you need socket based communications then make sure there is not an easier option than writing your own. If you need to support multiple legacy clients then you may have to go this route but check and see if there are any applicable third-party libraries you can use.

But if you need to write your own then this article will teach you how to do it in .NET using C#. We will look at more advanced techniques in .NET socket communications. If you only need a basic listener and client you should look into the Socket helper classes. These include the TcpClient, TcpServer and UdpClient classes in the Sockets namespace. Since UDP is connectionless there is no listener and the same class is used for your client and server. These classes are still powerful and will fulfill most production needs with few lines of code and fewer options and parameters to know.

Many programs of this type are written in C or C++. While the technology in .NET socket applications is not actually simpler than C++, it is simpler for you to write and maintain them in C# because .NET provides better abstraction of the underlying Win32 API functions.

NEXT>>

Home  • MSDN Blog  • Professional Biography  • Personal Biography  • Articles  • Technology  • White Papers  • Downloads  • Contact  • Terms of Use  • Site Map

Channel9  • Spock  • Google  • Programmer's Heaven  •  Variable Markup  • Wuup.de  • Pure  • Net Informations  • San24  • Yahoo Profile  • Excite UK  • Imprese  • NodeWorks  • Travel.com  • Amazon  • Geocities  • T-Links  • SearchBug  • Katalog  • Alexa Search  • Alexa Details  • 15 Seconds  • Blogwise  • Yahoo Profile  • FindArticles  • Julson  • Google Search  • Programmers Heaven author  • Alexa Browse  • MSN  • C9  • Eaton FL  • LinkSpider  • Macopinion  • Italy Link  • DerKeiler  • Programming-X  • CitiBay  • 15S  • Wils Domain  • AdvOL  • Computers Global  • TutorGig  • TGZ  • MV-S  • Deerlake  • mkiwi  • UKFindit • MWTT  • NetInfo • BSC  • WebBozo  • CVCS  • HotLaunch  • Escanaba • Google • FotoPages  • Conk  • InfoBase  • ExciteUK  • Angelfire  • BlogWise  • Canadian Content  • Opera Portal  • oStats  • 411 ASP  •  Interactiva  • Data Mining  • Call Center Forecasting  •  Accounting  • Guitar  • Computers Global  • BIE  • NewsIsFree Alph  • PX Java  • Trexle  • So-Ft  • DMOZ  • Programmer's Heaven Articles  • DotNetKuwait