Socket Programming with TCP

Now that we have looked at a number of important network applications, lets explore how network application programs are actually written. We'll write application programs that use TCP; in the following we'll write programs that use UDP.
Recall from many network applications consist of a pair of programs-a client program and a server program-residing in to different end systems. When these two programs are executed, .a client and a server process are created, and these processes communicate with each other by reading from and writing to sockets.

When creating a network application, the developer's main task is to write the code for both the client and server programs, There are two sorts of network applications. One sort is an implementation of a protocol standard defined in, for example, an RFC. For such in implementation, the client and server programs must conform to the rules dictated by the RFC. For example, the client program could be an implementation of the client side of the FTP protocol the server program could be an implementation of the FTP server protocol, also explicitly defined in RFC 959. If one developer writes code for the client program and an independent developer writes code for the server program, and both develop- en carefully follow the rules of the RFC then the two programs will be able to interoperate. Indeed, many of today's network applications involve communication between client and server programs that have been created by independent develop- en-for example, a firefox browser communicating with an Apache Web server, or an FI'P client on a PC uploading a file to a Linux FTP server. When a client or server program implements a protocol defined in an REC, it should use the port number associated with the protocol. The other sort of network application is a proprietary network application. In this case the application-layer protocols used by the client and server programs do not necessarily conform to any existing RFC.'A single developer (or development team) creates both the client and server programs, and the developer has complete control over what goes in the code. But because the code does not implement a public-domain protocol, other independent developers will not be able to develop code that interoperates with the application. When developing a proprietary application, the developer must be careful not to use one of the well-known port numbers defined in the RFC.

We examine the key issues in developing a proprietary client-server application. During the development phase, one of the first decisions the developer must make is whether the application is to run over TCP or over UDP. Recall that TCP is connection oriented and provides a reliable byte-stream channel through which data flows between two end systems. UDP is connectionless and sends independent packets of data from one end system to the other, without any guarantees about delivery.

We develop a simple client application that runs over TCP we develop a simple client application that runs over UDP. We present these simple TCP and UDP applications in Java. We could have written the code in C or C++, but we opted for Java mostly because the applications are more neatly and cleanly written in Java. With Java there are fewer lines of code, and each line can be explained to the novice programmer without much difficulty but there is no need to be frightened if you are not familiar with Java. You should be able to follow the code if you have experience programming in another language. For readers who are interested in client/server programming in C, there are several good references available [Donahoo 2001; Stevens 1997; Frost 1994; Kurose 1996].

Labels:



Leave A Comment:

Copyright © Computer.