0% found this document useful (0 votes)
2 views18 pages

Networking

The document covers Java network programming, focusing on the java.net package, connection-oriented transmission using sockets, and client-server architecture. It explains key networking concepts, terminologies, and provides examples of client and server programs. The document also highlights the features of connection-oriented transmission and the sequence of communication execution in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views18 pages

Networking

The document covers Java network programming, focusing on the java.net package, connection-oriented transmission using sockets, and client-server architecture. It explains key networking concepts, terminologies, and provides examples of client and server programs. The document also highlights the features of connection-oriented transmission and the sequence of communication execution in Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JAVA NETWORK

PROGRAMMING
POINTS TO BE COVERED -
• [Link] package,
• Connection oriented transmission –
• Stream,
• Socket Class,
• Creating a Socket to a remote host on a port,
(creating TCP client and server),
• Simple Socket Program Example
NETWORK -
• Connection between two or more machines which can communicate
with each other
• To share resources like data, memory, processor power
• Two basic methods used for communication –
• Connection Oriented
• Connectionless
• Network is formed using different hardware and software
components
• Hardware – LAN card, wifi sensor
• Software – protocols
• Basic types of network - LAN-MAN-WAN
CLIENT-SERVER ARCHITECTURE -
• Centralized Network
• Many computers (Clients) are
connected to a computer with High
configuration (Server)
• Clients (remote processors)
request and receive services from
a centralized server (host
computer)
PEER TO PEER NETWORK
• Decentralized network
• Allows the participants to conduct
transactions without needing a central
server.
• The peers or nodes (usually a
computer) communicate with each
other on the network freely without an
intermediary.
NETWORK TERMINOLOGIES -
• MAC Address –
• Unique identifier assigned to a network interface card, written in hexadecimal.
• IP Address –
• Logical address that identifies a device on a network (e.g., [Link]). Range:
[Link] – [Link].
• Protocol –
• Set of rules for communication (e.g., TCP, FTP, HTTP).
• Socket –
• A socket is one endpoint of a two-way communication connection between the
two applications running on the network.
• The socket mechanism presents a method of inter-process communication (IPC)
by setting named contact points between which the communication occurs.
• Port –
• A socket is tied to a port number so that the TCP layer can recognize the
application to which the data is intended to be sent.
NETWORK TERMINOLOGIES -
• Connection Oriented Protocol–
• In a connection-oriented service, the user must establish a connection
before starting the communication. When the connection is established, the
user can send the message or the information, and after this, they can
release the connection.
• Example of Connection-oriented Protocol – Transmission Control Protocol
(TCP)
• Connectionless protocol –
• In connectionless protocol, the data is transported in one route from source
to destination without verifying that the destination is still there or not or if it
is ready to receive the message. Authentication is not needed in the
connectionless protocol.
• Example of Connectionless Protocol – User Datagram Protocol (UDP)
• URL –
• A URL, or Uniform Resource Locator, is essentially the web address you type
into your browser's address bar to visit a website.
NETWORKING APPLICATIONS -
• Network Applications – The software that runs on two
machines
• Types of network Applications –
• Network Applications – Works on private network like LAN
• Web Applications – Works on internet through browser
[Link] PACKAGE -
• Java provides the classes and interfaces in the package
‘[Link]’ for implementing networking applications which
offers tools for –
• Establishing connections,
• Handling data transfer,
• Interacting with network addresses.
• [Link] provides the building blocks for creating
networking applications in Java, from simple client-server
communication to more complex scenarios involving
multicast or other specialized protocols.
[Link] PACKAGE – KEY FEATURES
• Support for both type of connections -
• Connection Oriented (TCP/IP Protocol)
• Connection less protocol (User Datagram Protocol)
• Low-Level API : Provides fundamental networking concepts like addresses (IP
addresses), sockets (bidirectional data communication), and interfaces (network
interfaces).
• Sockets: The package provides various socket classes for different network
protocols, including -
 Socket: For TCP client-side connections.
 ServerSocket: For TCP server-side connections, accepting client connections.
 DatagramSocket: For UDP (connectionless) communication.
 MulticastSocket: For multicast networking.
• Addresses:
• The InetAddress class represents network addresses.
• URL and URLConnection: These classes enable working with Uniform Resource
Locators (URLs), allowing access to data at specified network locations.
• Interfaces: The package provides classes to work with network interfaces, providing
information about available network connections.
CONNECTION ORIENTED TRANSMISSION WITH STREAMS
• In the context of connection-oriented networking, a stream socket
utilizes the Transmission Control Protocol (TCP) for data transmission.
• Stream sockets provide a reliable, ordered, and bidirectional flow of
data between two processes on a network, much like a pipe.
• The Socket and ServerSocket classes are the key classes used for
connection-oriented socket
FEATURES OF CONNECTION ORIENTED TRANSMISSION
• Connection-Oriented:
A connection must be established between the client and
server before data can be exchanged. This is typically done
using the TCP protocol.
• Reliable:
TCP ensures that data is delivered without errors, in the
correct order, and without duplication.
• Bidirectional:
Data can flow in both directions between the client and
server.
• Byte Stream:
Data is transmitted as a continuous stream of bytes,
without any record boundaries.
CLASSES USED IN COMMUNICATION -
• Socket Class:
The Socket class is used to represent a socket, which is an
endpoint of communication.
• ServerSocket Class:
The ServerSocket class is used to listen for incoming connection
requests from clients.
SEQUENCE FOR EXECUTION OF COMMUNICATION
1. Server Creates a ServerSocket:
The server creates a ServerSocket object and binds it to a specific port
number. This tells the server which port to listen for incoming connections on.
2. Client Creates a Socket:
The client creates a Socket object and connects it to the server's IP address and
port number.
3. Connection Established:
Once the client and server successfully connect, a stream socket is established
between them, allowing for reliable data transfer.
4. Data Transfer:
Data can be read from and written to the socket using input and output streams.
COMMUNICATING ON NETWORK THROUGH JAVA
PROGRAMS
PROGRAM TO ESTABLISH CONNECTION BETWEEN
CLIENT AND SERVER
CLIENT SIDE PROGRAM -
import [Link].*;
public class ClientConnect {
private Socket clientSocket = null;
public ClientConnect (String addr, int port)
{
// Establish a connection
try {
clientSocket = new Socket(addr, port);
[Link]("Connected");
}
catch (UnknownHostException u) {
[Link](u);
return;
}
public static void main(String[] args) {
ClientConnect c = new ClientConnect ("[Link]", 5000);
}
}
SERVER SIDE PROGRAM
public static void main(String args[])
import [Link].*;
{
Import [Link].*;
ServerConnect s = new ServerConnect(5000);
public class ServerConnect {
}
private Socket clientSocket = null;
}
private ServerSocket serverSocket = null;
public ServerConnect(int port) {
// Starts server and waits for a connection
try
{
serverSocket = new ServerSocket(port);
[Link]("Server started");
[Link]("Waiting for a client ...");
clientSocket = [Link]();
}
catch(IOException i)
{
[Link](i);
}

You might also like