Infolinks In Text Ads

Wednesday 17 August 2011

Network Programming in .NET


Basic concepts of network programming
 To set up a communication channel between two computers, we will need a pair of endpoints, and a communication protocol (some way of interpreting the data, and a way of establishing the connection between the two endpoints, and a way of ending the “conversation” politely).   One such communication protocol is called TCP  (Transport Control Protocol).  We leave it to your networking course to supply details about TCP and TCP/IP, but .NET makes it possible to write network programs without knowing anything about TCP.   There exist other communication protocols, but we will use only TCP in this lecture.
 To summarize:  to create a usable communications channel we need two endpoints and a protocol,  or otherwise described, we need
  • A local IP address
  • A local port number
  • A remote IP address
  • A remote port number
  • A transport protocol
 A data structure that encapsulates these five things is called a “socket”.
The concept of “socket” is independent of .NET and even independent of Windows—every modern operating system has a way to construct sockets.
Sockets are provided for Windows in the Winsock library, and for Unix in the Berkeley sockets library.   The Winsock library functions are wrapped in the .NET Socket class.
 The Socket class also provides a Connect method.   That in turn calls on ancient code in the Winsock library to establish a connection between the local endpoint and the remote endpoint.   That,  of course, is only going to work if the remote endpoint is “listening”,  i.e.  is ready to receive a connection request and do its part to establish the connection.
Once we have successfully established a connection to a remote endpoint, we can use the Socket class method Receive to receive data.

Twitter Delicious Facebook Digg Stumbleupon Favorites More