Tutorial 7 -Network Programming in Java

In this tutorial, network programming is explained using a simple client server example. For connecting between the client and the server we use windows sockets. 

A Socket is a communication end-point unique to a machine communicating on an Internet Protocol-based network, such as the Internet. All applications communicating through the Internet use a network socket. The feature that distinguishes a network sockets from other sockets is the protocols that it supports. The supported protocols are:

  1. TCP
  2. UDP
  3. Raw IP

The difference between them is based on whether the protocol is connection oriented or not.

TCP protocol guarantees reliable and in-order (correct order of packets) delivery of data from sender to receiver. To put it simply, it's reliable. The second aspect of TCP is that it is connection oriented. That means TCP requires that a connection be made between the sender and receiver before data is sent. The socket associated with TCP is known as the Stream Socket.

UDP, like TCP, is one of the core protocols of the IP suite. However, unlike TCP, it neither guarantees in-order delivery of data nor does it requires a connection to be established for sending the data. To put it simply, UDP is an unreliable and connectionless protocol. Sockets associated with UDP are known as Datagram Sockets.

Raw IP is a non-formatted protocol, unlike TCP and UDP. It works at network and transport layers. A socket associated with Raw IP is known as a Raw Socket. UDP and TCP sockets just receive the payload or the data, whereas Raw Sockets receive the header info of the packet along with the data. The downside of Raw Sockets is that they are tightly coupled with the implementation provided by the underlying host operating system.

Namespaces used

Java.net  :-  Provides the classes for implementing networking applications.

Some of the classes in this namespaces:

ServerSocket :- This class implements server sockets.

Socket    :-   This class implements client sockets (also called just "sockets").

DatagramSocket  :- This class represents a socket for sending and receiving datagram packets.

SocketAddress  :- This class represents a Socket Address with no protocol attachment.

 Check the Video Tutorial Online.

Download Source of Network programming


Download Java In Easy Steps Video Tutorials