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

IP-based communication programming involves two basic categories of communications, connectionless and connection-oriented. The types of solutions we are discussing here use a connection oriented SOCK_STREAM type socket over TCP versus a connectionless SOCK_DGRAM type socket over UDP.

Our socket communication will follow the following steps.

1) Create a socket
2) Bind the socket to an address or end point
3) Listen for an incoming communications attempt
4) Accept the communication
5) Send and receive messages buffers
6) Shutdown the communication channel
7) Close the socket connection

You will need to add the statement “using System.Net;” to the top of your classes to try out the techniques listed here. This is the namespace containing most the classes you are going to need to create our sockets and manage the communications.

Each of the parties in a socket communication is called and end point. When you create your endpoint you need to decide which address family you are using. This specifies which addressing scheme that a socket will use to resolve an address. The one you will most likely use is "InterNetwork" which indicates that you are using IP version 4 such as what is used on most Ethernet networks and the Internet (e.g. 10.0.0.1). .NET and the .NET compact framework support a lot of addressing schemes out of the box. Some of the more useful and interesting ones include AppleTalk, ATM, Banyan, Data Link, ECMA, InterNetworkV6, NetBIOS, OSI and SNA. You can also specify "Unknown" and "Unspecified." This article addresses only “InterNetwork” addressing but the concepts detailed here transfer to the other address family types.

Each endpoint has a unique address which is a combination of an IP address and a port number. You will need the local IP addresses of your devices for communication to occur. There is an IPAddress class which you can instantiate it by passing the value of your IP address as a byte array or a long. If you need to pass in a string as your values then there is a parse method which is shown below.


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