Chapter 20 dealt with Web services, describing how to send messages from the client to the server in a platform-independent way with the SOAP protocol. In this chapter, you step into lower networking layers, programming with classes from the namespace System.Net. Web services itself uses this technology.

This chapter begins with an overview of programming client and server applications with classes from the namespaces System.Net and System.Net.Sockets, which make use of protocols such as HTTP, TCP, and UDP. You will cover both connection-oriented applications with TCP and connection-less applications with the UDP protocol.

In this chapter, you learn about:

  • An overview of networking
  • Networking programming options
  • Using WebRequest
  • TcpListener and TcpClient
  • Socket programming

Networking Overview

Networking is about communicating with applications on other systems. The communication happens by sending messages. Messages can be sent to a single system where a connection is initiated before the message, as shown in Figure 29-1, or messages can be sent to multiple systems by a broadcast, as shown in Figure 29-2. With a broadcast, connections are not initiated, the messages are just sent to the network instead.

Networking can be best illustrated by showing the seven OSI layers. Figure 29-3 shows the stack of the OSI layers with their corresponding TCP/IP layers. Often the layers are also defined by numbers that are simply increments of the layers from bottom, where the ...

Get Beginning Visual C#® 2005 now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.