Pages

Thursday, March 17, 2011

TCP/IP, UDP & Multicasting Through Java's Socket

TCP/IP, UDP & Multicasting Through Java's Socket

Part I - Basic Networking through Java

Introduction

Since birth of network programming, it has been error-prone, difficult, and complex. The programmer had to know many details about the network and sometimes even the hardware. You usually needed to understand the various layers of the networking protocol, and there were a lot to different functions in each networking library concerned with connecting, packing, unpacking blocks of information, handshaking, etc. It was a difficult task. However, the concept of networking is not so difficult. You want to get some information from that machine over there and move it to this machine here, or vice-versa. Its quite similar to reading and writing files, except that the files exist on the remote machine.

One of Java's great strengths is painless networking. As much as possible, the underlying details of networking have been abstracted away. The programming model we use is that of the file programming model. In addition, Java's built-in multithreading is exceptionally handy when dealing with another networking issue: handling multiple connections at once. The java.net package includes classes that enable the programmer to easily pass data across networks.

Networking Concepts

The primary function of the TCP/IP is to provide a point to point communication mechanism. One process on one machine communicates with the another process on another machine or within the same machine. This communication appears as two streams of data. One stream carries data from one process to the other, while the other carries data in the other direction. Each process can read the data that have been written by the other, and in normal conditions, the data received are the same, and in the same order, as when they are sent.

In order to tell one machine from another machine and to make sure that you are connected with the machine you want, there must be some way of uniquely identifying machines on a network. Early networks were satisfied to provide unique names for machines within the local network. However, Java works within the Internet, which requires a way to uniquely identify a machine from all the others in the world. This is accomplished with the IP ( Internet Protocol ) address, a 32 bit number.

IP Address in two forms :

* The DNS ( Domain Name Service ) form. Suppose, if my domain name is calsoftlabs.com and if I have a computer called Hari in my domain. Its domain name would be Hari.calsoftlabs.com.
* Alternatively, we can use dotted quad form, which is four numbers separated by dots, such as 199.2.24.246

In addition to the machine addresses provided by the Internet Protocol part of the network system, TCP/IP has a mechanism for identifying individual processes on a machine, analogous to an office block. The building has phone number , but each room inside is also identified by an extension number. When a call arrives at the building, it must be connected to the correct room for handling . Payment requests go to accounts payable, orders to sales, and so forth. In the TCP/IP system, the extension numbers are called ports, and they are represented by a 16-bit binary number. To communicate with the correct part of a particular computer, the sending machine must know both the machine address and the port number to which the message should be sent. Many common services have a dedicated port. Because some ports are reserved for common services, the programmer cannot use any port. Ports numbered under 1024 are often referred to as reserved ports, many of which are reserved for a specific program. It is important that you only attempt to use ports over number 1024.

Download

Download full seminar papers At
http://www.enjineer.com/forum

No comments:

Post a Comment