Networking Tutorial Port Protocol
Summary: Networking is a big subject with confusing general concepts like port number and protocol etc. for a beginner. These concepts are explained in simple terms in this "Networking Tutorial Port Protocol".
Networking is the process of connecting different computer devices like printers and systems to make it convenient for communication to share the resources available with them. For smooth communication, both hardware and software should collaborate. Hardware includes network interface cards (NIC), routers etc. and software includes a network supporting operating system like Windows NT or UNIX etc.
Computers can be demarcated taking different factors into consideration. This classification is more relevant to a hardware engineer rather than a software engineer.
- Basing on area operated: WAN (Wide Area Network), CAN (Campus Area network), MAN (Metropolitan Area Network), LAN (Local Area Network) and PAN (Personal Area Network) etc.
- Basing on topology: Star network, Tree and Linear network, Ring network, Mesh network etc.
- Basing on relationships: Workgroup, Client-server and Active networking etc.
- Basing on hardware: Wireless, Optical fiber and Ethernet etc.
Network programming involves understanding of some basic terms like IP address, Port number and Socket etc.
Understanding IP address
To convey the data exactly to the system it is intended, the system requires an address known as IP Address. It must be unique in the network (like your house address is unique on the planet, else, a letter posted in USA cannot reach your house). The IP address is denoted by four integer values (ranging from 0 to 255) separated by three dots like 127.0.200.80. Alternatively, a system can be given a name also as names can easily be remembered in place of addresses of 12 digits. It is easy to remember rediff.com instead of its IP address 18.104.22.168.
In day-to-day life, a protocol is the manners you should follow while speaking to others. For example, definitely you accept, the way you speak with your friend is quiet different from the way you speak to your faculty and which again differs the way you speak to your Principal. The protocol is nothing but the rules (syntax) of communication between the systems. For example, the HTTP protocol dictates the rules between the systems that communicates using Internet (Web), say, the client should reveal who it is and allows redirection when the source is shifted to another Web server (status code 301 and 302). The other popular protocols are IP (Internet Protocol), SMTP (Simple Mail Transfer Protocol) used to upload the email messages and POP3 (Post Office Protocol) used to download the email etc.
Perception of Port Number
A port number recognizes a process being executed on the system, say, a server system. On the server, different processes being executed are identified by different port numbers. This port number is used by the client to ask the server which process (running on the server) it would like to connect. When the client specifies the port number when it requests, the server automatically connects the client to that process. A port number must be within the range of 0 to 65,535.
Note: IP address identifies the system in the network and the port number identifies the process running on the system. Both are very different.
Well-known Port Numbers
There is an authority which assigns the IP addresses for different servers in the world. It is IANA (Internet Assigned Numbers Authority). To make the understanding and programming simple, the IANA allotted some port numbers to certain protocols used very often like 80 for HTTP, 20 for FTP and 23 for Telnet etc. These port numbers are known as well-known port numbers and ranges between 0 and 1023.
Advantages of Networking
Due to networking following are possible.
- Primary advantage is communication.
- The resources can be shared.
- Hardware can be shared. One printer can be used by many systems.
- If one Internet connection exists, all systems can share the connection.
- Data is secured as the systems within the network only can share.
- In a call center, the calls from the clients can evenly be distributed using load balancing servers.
Disadvantages of Networking
Networking comes with a few disadvantages which are not serious before the advantages it gets.
- Initial costs are very heavy for hardware and software.
- Requires system administrator and networking people and thereby maintenance cost increases.
- As systems are shared, no privacy exists.
The following terms are used generally in computer networking which sometimes confuses a novice.
A host is simply a system in the network having an IP address. It need not be a server. It can be any system.
A Console is a terminal commonly used to refer to a keyboard or display monitor.
This statement written anywhere in the code, terminates the whole process (application). The parameter 0 specifies a normal shutdown and any other integer value specifies abnormal shutdown. System.exit(0) is very extensively used in AWT to close the frame.
Networking classes – java.net package
Java is used everywhere, for example, in the NetWeaver portal of SAP and Java methods can be used instead of stored procedures of Oracle etc. Another feather to the cap, Java is a very strong supporter of networking. It supports Internet communication through servlets and JSP and distributed communication through RMI/EJB. To support LAN programming (also known as socket programming), Java API comes with a package java.net with many classes like Socket, ServerSocket, DatagramPacket, URL and URLConnection etc. These classes support both TCP/IP and UDP protocol. The next programs use all these.
Java Exceptions in networking
Two exceptions are of primary importance in networking – MalformedURLException and UnknownHostException.
The MalformedURLException is raised when the URL address of the server given is in wrong format and UnknownHostException is raised when the client is unable to locate the server due to wrong address. Both are subclasses of IOException and are from java.net package.