EXPERIMENT-01
TCP &
UDP
TCP-
Transmission Control Protocol
TCP is one
of the main protocols in TCP/IP network. TCP enables two hosts to establish a
connection and exchange steam of data. TCP guarantees delivery of data and also
ensure that they are sent in the same order. The unit of data transferred is
called a steam which is simply a sequence of bytes.
Being
connection oriented means that before actually transmitting data, we must open
the connection between the two end points. The data transfer cannot take place
before both ends have agreed upon the connection. The connection can be closed
from either side.
Being
steream oriented means that the data is anonyumous sequence of bytes. There is
nothing to make data boundaries apparent. The data sent is without any error
and in correct order.
ADVANTAGES
OF TCP:
1. The operating system does all the work. No
need to have the same bugs in your code that everyone else had, its all been
already figured out.
2. It guarantees three things:-
1) That your data gets there.
2) It gets in order.
3) It gets without duplication.
3. TCP has good throughput on a modem or LAN.
DISADVANTAGES OF TCP:
1. The operating system may be buggy and
you can’t escape that. You have to put up with it.
2. TCP has no block boundaries; we need
to create our own.
3. TCP cannot be used for broadcast or
multicast.
UDP:
It stands for User Datagram Protocol, a
connectionless protocol that like TCP runs on the top of the I/P network.
Unlike TCP/IP, UDP/IP provides a few error recovery services, offering instead
a direct way to send and receive datagrams over an IP network. It’s used
primarily for broadcasting messages over an I/P network. It’s used primarily
for broadcasting messages over a network.
UDP provides
a connection-less host-host communication path. UDP has minimal overhead; each
packet on the network is composed of a similar header and user data. It is
called a UDP datagram.
UDP is
connectionless. It means that a datagram can be sent at any moment without
prior advertising negotiation or preparation. UDP is unreliable protocol. There
is absolutely no guarantee that the datagram will be delivered to the
destination host.
ADVANTAGES
OF UDP
1) It does not restrict you to a
connection based communication modem.
2) All flow control, making the
transactions logging etc is up to user programs.
3) Broadcast and multicast transmission
are available.
DISADVANTAGES
OF UDP:
1) There is no guarantee with UDP, a
packet may not be delivered, or delivered twice or delivered out of order.
2) It has no flow control.
Implementations are the duty of user program.
COMPARISON:-
TCP
|
UDP
|
·
Connection
oriented
·
Reliability in
delivery of messages.
·
keep track of
order
|
·
Connection less
·
No attempt to
fragment messages.
·
In case of error
message is retransmitted.
|
EXPERIMENT-02
FTP, HTTP & TELNET
FTP:-
FTP is an acronym for File
Transfer Protocol. As the name suggests FTP is used to transfer files between
computers on a network. You can use FTP to exchange files between computers
accounts, transfer files between an account and a desktop computer or access
online software archives.
WAY TO USE FTP:
Web-Browser: you can use a web browser to connect to FTP
addresses exactly as you would to connect to HTTP addresses. To use it we may
write
Graphical FTP client:-
It simply file transfers
by allowing you to drag and drop files icon between windows. When you open the
program enter the name of the FTP host and your username and password.
MODES OF DATA TRANSFER:-
·
Stream Mode: data
is sent as a continuous stream, relieving FTP from doing any processing.
·
Block Mode: FTP
blocks the data into several blocks and then passes it to TCP.
·
Compressed Mode:
Data is compressed using a single algorithm.
HTTP:
It stands for Hyper Text
Transfer Protocol.
Computer on world wide web
use the hypertext transfer protocol to talk with each other. The HTTP provides
a set of instructions for accurate information exchange. The HTTP connects
computer network and allows them to communicate.
VERSIONS:
The first version of HTTP
refused to as HTTP/0.9 was a simple protocol for raw data transfer across the
internet HTTP/1.0 improved the protocol by allowing messages about the data
transfers. The specifications defines the protocol as HTTP/1.1 in order to
ensure reliable implementations of its features.
HTTP SESSION STATE:
HTTP is a stateless
protocol. The advantages of stateless protocol is that hosts do not need to
retain information about users between requests. But a web application must be
written to track users progress from state to state. A common method to solve
this is send and receive cookies.
TELNET:
TELNET is a user command
and an underlying TCP/IP protocol for accessing remote computers. Through
telnet, an administrator or another user can access someone elses computer
remotely. With telnet you log on as a regular user with whatever privilages you
have been granted.
The term telnet may also
refer to the software that implements the client part of the protocol.
THE APPLICATIONS ARE:-
1. Enterprise network
2. Internet games
3. Administration of network element.
HOW TELNET WORKS:
TELNET uses a software installed on your computer to create
a connection with the remote host. The telnet client at your command will send
a request to the server. The telnet client will establish a connection to the
host thus making your computer a virtual terminal and allowing you to complete
the access
EXPERIMENT-03
AIM: To perform the client-server communication
using TCP/IP protocol.
Algorithm:
1. Received the messsageFrom user.
2. Send the message to server
3. Receive the acknowledgement from server.
4. Display on server side.
PROGRAM:
import java.io.*;
import java.net.*;
classclienttcp
{
public static void
main(String argv[]) throws Exception
{
String sentence;
String modifiedSentence;
BufferedReaderinFromUser=new
BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new
Socket("192.168.3.111",6789);
DataOutputStreamoutToServer=new
DataOutputStream(clientSocket.getOutputStream());
BufferedReaderinFromServer=new
BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
sentence=inFromUser.readLine();
outToServer.writeBytes(sentence
+ '\n');
modifiedSentence=inFromServer.readLine();
System.out.println("FROM
SERVER:"+modifiedSentence);
clientSocket.close();
}
}
import java.io.*;
import java.net.*;
classstcp
{
public static void
main(String args[])throws Exception
{
String clientSentence;
String
capatalizedSentences;
ServerSocketWelcomeSocket
= newServerSocket(6789);
while(true)
{
SocketConnectionSocket =
WelcomeSocket.accept();
BufferedReader inform
client = new BufferedReader(new InputStreamReader(ConnectionSocket.getInputStream()));
DataOutputStram out to
client = new Data Output Stream(ConnectionSocket.getOutputStream());
ClientSentence = inform
Client.readline();
System.out.println("Recieved"+clientSentence);
Capatalized Sentence =
ClientSentence to uppercase()+'\n\;
outToclient.WriteBytes(CapatalizedSentence);
}
}
}
INPUT/OUTPUT:
CLIENT SIDE:
C:\jdk1.6\bin\javac
ctcp.java
C:\jdk1.6\bin>java ctcp
Hello
FROM SERVER: HELLO
Server side:
C:\jdk1.6\bin\javac
stcp.java
C:\jdk1.6\bin>java stcp
Received:
RESULT: The client server
program has been successfully executed.
EXPERIMENT -04
AIM: To perform the client server using UDP.
Algorithm:
1. Send the request to server.
2. Receive the retrieve data from server.
3. Display the message.
Program:
Client:
import java.net.*;
import java.io.*;
classudpclient
{
public static void
main(String args[])throws Exception
{
DatagramSocketdsoc=new
DatagramSocket(24);
byte buff[]=new
byte[1024];
DatagramPacketdpack=new DatagramPacket(buff,buff.length);
dsoc.receive(dpack);
System.out.println(new
String(dpack.getData()));
}
}
Server:
importjava.util.*;
import java.io.*;
import java.net.*;
classudpser
{
public static void
main(String args[])throws Exception
{
DatagramSocketdsoc=new DatagramSocket(5217);
InetAddress
host=InetAddress.getLocalHost();
String str=(new Date()).toString();
bytebuf[]=str.getBytes();
DatagramPacketdpack=new
DatagramPacket(buf,buf.length,host,24);
dsoc.send(dpack);
dsoc.close();
}
}
INPUT/OUTPUT:
C:\jdk1.6\bin\javac
Udpserver.java
C:\jdk1.6\bin\java Udpserver
Wed Aug25 11:05:15 IST
2010
RESULT: Thus the program
has been successfully executed.
EXPERIMENT-05
AIM: To fetch date and
time from server using TCP/IP
protocol.
Algorithm:
SERVER:
1.
Make the
connection.
2.
Store the date
and time in buffer
3.
Transfer the date
and time to client.
Client:
1.
Make the
connection.
2.
Store the date
and time in buffer.
3.
Receive the date
from server.
4.
Close the
connection.
PROGRAM:
Server:
import java.net.*;
import java.io.*;
importjava.util.*;
classdateser
{
public static void
main(String args[])throws Exception
{
ServerSocket s=new
ServerSocket(5217);
while(true)
{
System.out.println("waiting
for connection.......");
Socket soc=s.accept();
DataOutputStream out=new
DataOutputStream(soc.getOutputStream());
out.writeBytes("Server
Date"+(new Date()).toString()+"\n");
out.close();
soc.close();
}
}
}
Client:
import java.io.*;
import java.net.*;
classdateclient
{
public static void
main(String args[])
throws Exception
{
Socket soc=new Socket
(InetAddress.getLocalHost(),5217);
BufferedReader in=new
BufferedReader
(newInputStreamReader(soc.getInputStream()));
System.out.println(in.readLine());
}
}
INPUT/OUTPUT:
C:\documenta and
setings\cd1
C:\>cd jdk1.6
C:\>jdk1.6> cd bin
C:\>jdk1.6>bin>javac
dateclient.java
C:\jdk1.6>bin>java
dateclient
Server date Tue 1 Sept
22:14:52 IST
SERVER:
C:\documents and
settings\cd
C:\jdk1.6>cd bin
C:\>jdk1.6>bin>javac
dateser.java
C:\jdk1.6>bin>java
dateser
Waiting for connection……
RESULT: The program to
fetch date and time from server using TCP/IP protocol have been fetched
successfully.
SMTP AND POP3
SMTP:
It stands for simple mail
transfer protocol. It is an internet standard for electronic mail transmission
across internet protocol networks. It can be said as it is the set of
procedures needed for users to send mail from their networked computer to
remote computer.
PROTOCOL OVERVIEW:
SMTP is a text based
protocol in which a mail sender communicates with a mail receiver by issuing
command strings and supplying necessary data over a reliable ordered data
stream channel.
An SMTP session consists of commands originated by an SMTP
client and corresponding responses from the server. An SMTP transactions
consists of three commands.
1. MAIL command to return address.
2. RCPT to establish a recipient of this message.
3. DATA to send the message text.
SMTP Vs. MAIL RETRIEVAL
SMTP is a delivery
protocol only. It cannot pull messages from a remote server on demand other
protocol such as POP are especially designed for retrieving messaged.
POP3 (Version 3)
It stands for Post Office Protocol. It is an application
layer internet standard protocol used by local email clients to retrieve e-mail
from a remote server over a TCP/IP connection. POP supports simple download and
delete requirements for access to remote mail boxes. Although most POP clients
have an option to leave mail on server after download.
A POP3 mail server receives e-mails and filters than into
the appropriate user folder when a user connects to the mail server to retrieve
his mail the messages are downloaded from mail server to the users hard disk.
When you configure your email client such as
outlook or mail you will need to enter the type of mail your email accounts
users. This will be POP server.
Still most mail servers use the POP3 mail protocol because
it is simple and well supported.
EXPERIMENT-07
AIM: To perform chatting
application using UDP Protocol.
ALGORITHM:
Client:
1. Receive the message from the user.
2. Send the server.
3. Display on server side.
Server:
1.
Receive message
from client.
2.
Display the
message
PROGRAM:
import java.io.*;
import java.net.*;
importjava.util.*;
classser
{
public static void
main(String args[])throws Exception
{
BufferedReaderinFromUser=new
BufferedReader(new InputStreamReader(System.in));
DatagramSocketserverSocket=new
DatagramSocket(5217);
byte[ ] receiveData=new
byte[1024];
byte[ ] sendData=new
byte[1024];
while(true)
{
DatagramPacketreceivePacket=new
DatagramPacket(receiveData,receiveData.length);
serverSocket.receive(receivePacket);
String sentence=new
String(receivePacket.getData());
System.out.println("received"+sentence);
InetAddressIPAddress=receivePacket.getAddress();
int
port=receivePacket.getPort();
String
capitalizedSentence=inFromUser.readLine();
sendData=capitalizedSentence.getBytes();
DatagramPacketsendPacket=new
DatagramPacket(sendData,sendData.length,IPAddress,port);
serverSocket.send(sendPacket);
}
}
}
CLIENT:
import java.io.*;
import java.net.*;
importjava.util.*;
class cli
{
public static void main
(String args[ ]) throws Exception
{
BufferedReader user = new
BufferedReader (new InputStreamReader(System.in));
DatagramSocketclientSocket=new
DatagramSocket();
InetAddressipaddress =
InetAddress.getByName("localhost");
byte[ ] sendData=new
byte[1024];
byte[ ] receiveData= new
byte[1024];
while(true)
{
String sentence=
user.readLine();
sendData=sentence.getBytes();
DatagramPacketsendPacket=new
DatagramPacket(sendData,sendData.length,ipaddress, 5217);
clientSocket.send(sendPacket);
DatagramPacketreceivePacket=new
DatagramPacket(receiveData,receiveData.length);
clientSocket.receive(receivePacket);
String
modifiedSentence=new String(receivePacket.getData());
if(modifiedSentence=="terminate")
{
clientSocket.close();
}
System.out.println("from
server" + modifiedSentence);
}
}
}
INPUT/OUTPUT:
C:\jdk1.6\bin>javac
ser.java
C:\jdk1.6\bin>java ser
Received hello
Hi received hows life
C:\jdk1.6\bin>javac
cli.java
Hello
From server hi
hows life
RESULT: the program has been
successfully executed.
SINGLE SOURCE SHORTEST PROGRAM
Aim: write a program to
implement the single source shortest
path algorithm
No comments:
Post a Comment