I realised that programming in Java is quite a fun only after doing it myself. You will be amazed to know that it’s like putting different pieces of puzzle together. You put them relatively in an integrated and coherent manner. The Beauty of it is, that most of the times you dont have to create these pieces yourself. You just customize them according to your need after you get them from an already defined java class or package. It was about programming, now lets talk sumthing about sockets.
Socket is used to establish a point-to-point, bidirectional connection between two entities in a network. Just like a real world socket, it is used to plugin a connection from another source. The connection can be incoming or outgoing or both. Similar is the case at the other end. To understand these sockets properly, you need to learn a bit about Operating System and its Networking Protocols. Sockets are basically of three types: 1)UNIX Domain Sockets; 2) Internet Domain Sockets; 3) NS domain Sockets.
Java being platform independent Programming language, supports only Internet Domain Sockets as only they are platform independent out of three. These internet domain sockets are distinguished on the basis of Internet protocol they work on…
1) TCP/IP(Transfer Control Protocol): The data transfer is reliable, in-order,connection oriented, so takes connection establishment time before the actual data transfer takes place. Sockets based on TCP/IP are known as Stream Sockets.
2) UDP(User Datagram Protocol): It is connectionless,unrealiable and unordered data transfer protocol. Each packet in it has a destination address associated with it and is realeased into the network to make its own way. The sockets based on UDP are called Datagram Sockets.
3) Raw IP: It is a non-formatted protocol. Unlike TCP/IP, UDP protocols, Raw IP is not a core protocol of IP Suite. It’s different from them as its used to receive header information of the packet along with data, which is not the case in TCP/IP, UDP, they just receive data.
In Java Sockets are mainly implemented from already defined classes and pakages. These are:
1) Java.net.package: It contains all the classes that a user require to create a network based application. The below mentioned classes namely ServerSocket and Socket are also its part. This package also contain classes to create Secure Sockets and to connect a Web Server.
2) ServerSocket Class: It Provides sockets for the Server side.These sockets monitor network for requests or simply waits for them. When such request arrives, a server socket performs assigned task based on the request.
3) Socket Class: This class provides the Client side sockets. These sockets connect to the server, send and receive data for the client.
Remember, no socket can work without a port which is identified by a port no. Port is a gateway to a socket connectivity which is on the both sides of network. A socket is mainly identified as per its ports.