Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Understanding Sockets in Unix, NT, and Java

By Ken Nordby
2003-05-26


Sample sockets application

Let's look at three illustrative programs that constitute a simple client-server application based on sockets technology. This sample application is drawn from the Unix environment, and exploits the common Unix command man, which displays documentation about other Unix commands in the form of man pages. The purpose of the sample application is to make man pages available to users on non-Unix systems. Unix users are familiar with the man command, which retrieves documentation from the online Unix manual. For example, the command man sync displays documentation describing the purpose, syntax, and usage of the sync command.

Obviously the man command is intended to be run on Unix systems, because it displays documentation about Unix commands. What if a programmer working in a multi-platform environment wishes to retrieve man output while working on a Windows NT machine? Although this user requirement is artificial, the solution illustrates the capabilities of a client-server application based on sockets.

Client-Server Model
The sample application makes use of the client-server model of software design, which distributes the computing load across two or more machines. In the sample application, the server process runs on a Unix machine. The server process spends most of its time idle, waiting for a request from a client machine. The server opens a socket and makes it available on the network, providing addressability by hostname (bookworld) or by IP address (9.37.195.88). The server then goes into a quiesced listening mode. In this application the server is not entirely passive, because after every three idle minutes it notifies the user and prompts for approval to continue.

The sample application contains two client programs (one written in C++, one written in Java) that run on Windows NT machines. When a client is launched, it opens a socket and attempts to connect to the server process. On the local machine it prompts the user for a Unix command, which it transmits through the socket to the server. The server process constructs a man command string containing the client data, runs the command, and captures the output. The server transmits the output back to the requesting client, which displays it on the screen to the user. Thus, by way of sockets, the NT user has access to man page information while using a non-Unix machine. In this client-server configuration, all interprocess communication takes place by means of sockets.

Example of Unix man command



Command Input:
<xmp>
man sync
</xmp>
Command Output:
<xmp>
sync Command

Purpose

Updates the i-node table and writes buffered files to the hard disk.

Syntax

sync

Description

The sync command runs the sync subroutine. If the system must be stopped,
run the sync command to ensure file system integrity. The sync command
writes all unwritten system buffers to disk including modified i-nodes,
delayed block I/O, and read-write mapped files.

Note: The writing, although scheduled, is not necessarily complete
upon return from the sync subroutine.

Implementation Specifics

Software Product/Option: Base Operating System/ AIX 3.2 to 4.1 Compatibility
Links

Standards Compliance: OSF/1, OSF Level 3, BSD 4.3, SVID 3, SVID 2

Related Information

The sync subroutine.
</xmp>


Tutorial Pages:
» Understanding Sockets in Unix, NT, and Java
» Basic sockets concepts
» A simple example
» Sample sockets application
» Server program (Unix)
» Client program (NT)
» Client program (Java)
» Further study


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» All about JAXP, Part 1
» Make Database Queries Without the Database
» Load List Values for Improved Efficiency
» 2 Ways To Implement Session Tracking
» A Simple Way to Read an XML File in Java
» Develop Aspect-Oriented Java Applications with Eclipse and AJDT