Team Fly |
Page 317
|
Reading lines off the incoming stream synchronously is not a very efficient process either. The Stream object exposes the BeginRead/BeginWrite and EndRead/EndWrite methods, which are very similar to the asynchronous methods of the WebResponse object: they accept a delegate and they invoke it when the read/write operation has completed. You can edit the code of the application and make the read operations asynchronous as well.
The .NET Framework was designed from the ground up with the Internet in mind. It provides numerous tools that simplify the communication between remote systems, including the all-new Web services. In addition to the new ways of harnessing the Internet, the .NET Framework includes the basic classes that expose the traditional functionality of sockets.
In this chapter you've learned the basics of the Socket class, as well as how to use specific classes to exchange data with the TCP and UDP protocols. These classes are the TCPListener, TCPClient, and UDPClient classes and they abstract the basic operations you'd have to perform with traditional sockets to move data between two computers using the TCP and UDP protocols, respectively. The TCP protocol requires a dedicated connection, and each computer engaged in the conversation has a distinct role, either as a client or as a server. The UDP protocol is connectionless, and the computers involved in the conversation are all clients.
You've also learned how to use the WebClient, WebRequest, and WebResponse classes to interact with web resources from within your code. The WebClient class is the simplest one; it allows you to exchange data with a web server in a synchronous mode. The other two classes provide asynchronous methods, which enable you to write functional and responsive interfaces that interact with remote resources.
Team Fly |