<< Chapter < Page Chapter >> Page >

Although the distinction between client and server is becoming less clear each day, there is one fundamental distinction that is inherent in the Javaprogramming language.

The client initiates conversations with servers, while servers block and wait for a client to initiate a conversation.

The governing application-level protocol will determine what happens after the connection is made and the conversation has begun. The fact that the twocomputers can connect doesn't necessarily mean that they can communicate. In order to communicate, they must implement some mutually acceptable applicationprotocol

For example, the fact that I can dial a telephone number for a telephone located in France doesn't mean that I can communicate with the person whoanswers the phone. I don't know how to speak the French language. Unless the person who answers the phone speaks English, very little communication is likelyto take place.

Socket programming has been around for quite a while in the Unix world. Java simply makes it easier by encapsulating much of the complexity of socketprogramming into classes, and allowing you to approach the task on an object-oriented basis.

On the other hand, according to some authors, some of the generality and capability that Unix socket programmers have enjoyed has been lost in the encapsulation process.

Basically, socket programming makes it possible for you to cause data to flow in a full-duplex mode between a client and a server. This data flow can beviewed in almost exactly the same way that we view data flow to and from a disk: as a stream of bytes.

As with most stream data processing, the system is responsible for moving the bytes from the source to the destination. It is the responsibility of theprogrammer to assign meaning to those bytes.

Assigning meaning takes on a special significance for socket programming. In particular, as mentioned above, it is the responsibility of the programmer toimplement a mutually acceptable communication protocol at the application level to cause the data to flow in an orderly manner.

An application protocol is a set of rules by which the programs in the two computers can carry on a conversation and transfer data in the process. Forexample, we will also write a program that implements a very abbreviated form of the HTTP protocol to download web pages from a server and display them.

We will also write a program that functions as an (abbreviated) HTTP server to deliver web pages to a client and also supports the echo protocol for both TCP and UDP programming.

Each of these programs will involve adherence to a fairly simple protocol. (At least the part that we implement will be fairly simple) .

In addition, we will also write a program that obtains the date and time from another computer. In this case, the protocol will be about as simple as it canpossibly be. The client will simply make the connection and listen for a string containing the date and time. This will be sort of like dialing thelocal time service, except that we won't have to listen to an advertisement before getting the time.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask