CN and WP Lab Manual
CN and WP Lab Manual
CN and WP Lab Manual
MANUAL
III Year B.Tech. IT I-Sem
Course Outcomes
Implement data link layer farming methods
Analyze error detection and error correction codes.
Implement and analyze routing and congestion issues in network design.
Implement Encoding and Decoding techniques used in presentation layer
To be able to work with different network tools
COMPUTER NETWORKS PROGRAMS:
PROGRAM 1:
Implement the data link layer framing methods such as character, character-
stuffing and bit stuffing.
for(i=0;i<size;i++)
scanf("%d",&data[i]);
printf(" 01111110");
getch();
}
Output:
Enter the length of the datagram
20
Enter datagram with spaces in
between
111111110011100001
11
Stuffed data is:
011111101111100111110
Byte stuff program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char data[50][2],start[2],end[2];
int size,i;clrscr();
printf("Enter the starting character\n");scanf("%s",start);
printf("Enter the ending character\n");scanf("%s",end);
for(i=0;i<size;i++)
scanf("%s",data[i]);
printf("%c",end[0]);
getch();
}
Output:
Enter the starting character
D
Enter the ending character
G
Enter the length of the datagram
7
Enter datagram with spaces in between
GOODDAY
Stuffed data is:
DGGOODDDDAYG
PROGRAM 2:
Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and
CRC CCIP
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main() {
int i,j,keylen,msglen,flag=0;
char input[100], key[30],temp[30],quot[100],rem[30],key1[30];
printf("\n");
char temp1[20];
printf("enter recieved data:");
scanf("%s",temp1);
for (i=0;i<keylen;i++)
temp[i]=temp1[i];
for (i=0;i<msglen;i++) {
quot[i]=temp[0];
if(quot[i]=='0')
for (j=0;j<keylen;j++)
key[j]='0'; else
for (j=0;j<keylen;j++)
key[j]=key1[j];
for (j=keylen-1;j>0;j--) {
if(temp[j]==key[j])
rem[j-1]='0'; else
rem[j-1]='1';
}
rem[keylen-1]=temp1[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nQuotient is ");
for (i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
for (i=0;i<keylen-1;i++)
{
if(rem[i]=='1')
flag=1;
else
flag=0;
}
if(flag==0)
printf("\n no error");
else
printf("\nerror is detected");
getch();
}
Output1:
Enter Data: 10110111
Enter Key: 1001
Quotient is 10100011
Remainder is 011
Final data is: 10110111011
enter recieved data:10110111011
Quotient is 10100011
Remainder is 000
no error
output2:
Enter Data: 100100
Enter Key: 1101
Quotient is 111101
Remainder is 001
Final data is: 100100001
enter recieved data:100000001
Quotient is 111010
Remainder is 011
error is detected
PROGRAM 3:
Develop a simple data link layer that performs the flow control using the sliding
window protocol, and loss recovery using the Go-Back-N mechanism
#include<stdio.h>
int main()
{
Int w,I,f,frames[50];
Printf(“Enter window size: “);
Scanf(“%d”,&w);
Printf(“\nEnter number of frames to transmit: “);
Scanf(“%d”,&f);
Printf(“\nEnter %d frames: “,f);
For(i=1;i<=f;i++)
Scanf(“%d”,&frames[i]);
Printf(“\nWith sliding window protocol the frames will be sent in the following
manner (assuming no corruption of frames)\n\n”);
Printf(“After sending %d frames at each stage sender waits for acknowledgement sent
by the receiver\n\n”,w);
For(i=1;i<=f;i++)
{
If(i%w==0)
{
Printf(“%d\n”,frames[i]);
Printf(“Acknowledgement of above frames sent is received by sender\n\n”);
}
Else
Printf(“%d “,frames[i]);
}
If(f%w!=0)
Printf(“\nAcknowledgement of above frames sent is received by sender\n”);
Return 0;
}
Output:
Enter window size: 3
Enter number of frames to transmit: 5
Enter 5 frames: 12 5 89 4 6
With sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)
After sending 3 frames at each stage sender waits for acknowledgement sent by the
receiver
12 5 89
Acknowledgement of above frames sent is received by sender
46
Acknowledgement of above frames sent is received by sender
PROGRAM 4:
Implement Dijsktra’s algorithm to compute the shortest path through a network
#include <limits.h>
#include <stdio.h>
#include <stdbool.h>
#define V 9
return min_index;
}
dist[src] = 0;
sptSet[u] = true;
for (int v = 0; v < V; v++)
printSolution(dist);
}
int main()
{
/* Let us create the example graph discussed above */
int graph[V][V] = { { 0, 4, 0, 0, 0, 0, 0, 8, 0 },
{ 4, 0, 8, 0, 0, 0, 0, 11, 0 },
{ 0, 8, 0, 7, 0, 4, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 4, 14, 10, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
{ 8, 11, 0, 0, 0, 0, 1, 0, 7 },
{ 0, 0, 2, 0, 0, 0, 6, 7, 0 } };
dijkstra(graph, 0);
return 0;
}
Output:
1.Vertex Distance from Source
2 0 0
3 1 4
4 2 12
5 3 19
6 4 21
7 5 11
8 6 9
9 7 8
10 8 14
PROGRAM 5:
Take an example subnet of hosts and obtain a broadcast tree for the subnet.
#include <stdio.h>
int a[10][10],n;
void main()
int i,j,root;
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
scanf("%d",&root);
adj(root);
}
adj(int k)
int i,j;
printf("%d\n\n",k);
for(j=1;j<=n;j++)
if(a[k][j]==1 || a[j][k]==1)
printf("%d\t",j);
printf("\n");
for(i=1;i<=n;i++)
printf("%d",i);
}
Output:
Enter no.of nodes:4
Enter adjacent matrix
Enter connecting of 1–>1::0
Enter connecting of 1–>2::1
Enter connecting of 1–>3::1
Enter connecting of 1–>4::1
Enter connecting of 2–>1::1
Enter connecting of 2–>2::0
Enter connecting of 2–>3::1
Enter connecting of 2–>4::0
Enter connecting of 3–>1::1
Enter connecting of 3–>2::1
Enter connecting of 3–>3::1
Enter connecting of 3–>4::0
Enter connecting of 4–>1::1
Enter connecting of 4–>2::1
Enter connecting of 4–>3::1
Enter connecting of 4–>4::1
Enter root node:2
Adjacent node of root node::
2
1 3 4
PROGRAM 6:
Implement distance vector routing algorithm for obtaining routing tables at each
node.
#include<stdio.h>
#include<math.h>
#include<conio.h>
main()
{
int
i,j,k,nv,sn,noadj,edel[20],tdel[2
0][20],min; char
sv,adver[20],ch;
clrscr();
printf("\n ENTER THE NO.OF VERTECES:");
scanf("%d",&nv);
printf("\nENTER THE SOURCE
VERTEX NUMBER AND
NAME:");
scanf("%d",&sn);
flushall(); sv=getchar();
printf("\n NETER NO.OF ADJ
VERTECES TO VERTEX
%c",sv);
scanf("%d",&noadj);
for(i=0;i<noadj;i++)
{
printf("\n ENTER TIME DELAY and NODE NAME:");
scanf("%d %c",&edel[i],&adver[i]);
}
for(i=0;i<noadj;i++)
{
printf("\n ENTER THE TIME DELAY FROM %c to ALL OTHER
NODES:
",adver[i]);
for(j=0;j<nv;j
++)
scanf("%d",&
tdel[i][j]);
}
#include<stdio.h>
#include<math.h>
double min(double x, double y)
{
return(x<y?x:y);
}
double max(double x,double y)
{
return(x>y?x:y);
}
double gcd(double x,double y)
{
if(x==y)
return(x);
else
return(gcd(min(x,y),max(x,y)-min(x,y)));
}
long double modexp(long double a,long double x,long double n)
{
long double r=1;
while(x>0)
{
if ((int)(fmodl(x,2))==1)
{
r=fmodl((r*a),n);
}
a=fmodl((a*a),n);
x/=2;
}
return(r);
}
int main()
{
long double p,q,phi,n,e,d,cp,cq,dp,dq,mp,mq,sp,sq,rp,rq,qInv,h;
long double ms,es,ds;
do{
printf("\n Enter prime numbers p and q:");
scanf(" %Lf %Lf",&p,&q);
}
while(p==q);
n=p*q;
phi=(p-1)*(q-1);
do{
printf("\n Enter prime value of e:");
scanf(" %Lf",&e);
}
while((gcd(e,phi)!=1)&&e>phi); /*for e being relatively prime to
phi */
for(d=1;d<phi;++d)
{
if(fmod((e*d),phi)==1)
break;
}
printf("\n D within main = %Lf",d);
es=modexp(ms,e,n);
ds=modexp(es,d,n);
return(0);
}
Output:
Enter prime numbers p and q:223 101
Enter prime value of e:2213
D within main = 18077.000000
Enter the message:123
Original Message : 123.000000
Encrypted Message : 18415.000000
Decrypted Message : 123.000000
PROGRAM 8:
Write a program for congestion control using Leaky bucket algorithm .
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#define NOF_PACKETS 10
int rand1(int a)
{
int rn = (random() % 10) % a;
return rn == 0 ? 1 : rn;
}
int main()
{
int packet_sz[NOF_PACKETS], i, clk, b_size, o_rate, p_sz_rm=0, p_sz, p_time, op;
for(i = 0; i<NOF_PACKETS; ++i)
packet_sz[i] = rand1(6) * 10;
for(i = 0; i<NOF_PACKETS; ++i)
printf("\npacket[%d]:%d bytes\t", i, packet_sz[i]);
printf("\nEnter the Output rate:");
scanf("%d", &o_rate);
printf("Enter the Bucket Size:");
scanf("%d", &b_size);
for(i = 0; i<NOF_PACKETS; ++i)
{
if( (packet_sz[i] + p_sz_rm) > b_size)
if(packet_sz[i] > b_size)/*compare the packet siz with bucket size*/
printf("\n\nIncoming packet size (%dbytes) is Greater than bucket capacity
(%dbytes)-PACKET REJECTED", packet_sz[i], b_size);
else
printf("\n\nBucket capacity exceeded-PACKETS REJECTED!!");
else
{
p_sz_rm += packet_sz[i];
printf("\n\nIncoming Packet size: %d", packet_sz[i]);
printf("\nBytes remaining to Transmit: %d", p_sz_rm);
p_time = rand1(4) * 10;
printf("\nTime left for transmission: %d units", p_time);
for(clk = 10; clk <= p_time; clk += 10)
{
sleep(1);
if(p_sz_rm)
{
if(p_sz_rm <= o_rate)/*packet size remaining comparing with output
rate*/
op = p_sz_rm, p_sz_rm = 0;
else
op = o_rate, p_sz_rm -= o_rate;
printf("\nPacket of size %d Transmitted", op);
printf("----Bytes Remaining to Transmit: %d", p_sz_rm);
}
else
{
printf("\nTime left for transmission: %d units", p_time-clk);
printf("\nNo packets to transmit!!");
}
}
}
}
}
Output:
packet[0]:30 bytes
packet[1]:10 bytes
packet[2]:10 bytes
packet[3]:50 bytes
packet[4]:30 bytes
packet[5]:50 bytes
packet[6]:10 bytes
packet[7]:20 bytes
packet[8]:30 bytes
packet[9]:10 bytes
Enter the Output rate:15
Enter the Bucket Size:10
Incoming packet size (30bytes) is Greater than bucket capacity (10bytes)-PACKET
REJECTED
struct frame{
int fslno;
char finfo[20];
};
int n;
void sort()
int i,j,ex;
for(i=0;i<n;i++)
ex=0;
for(j=0;j<n-i-1;j++)
if(arr[j].fslno>arr[j+1].fslno)
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
ex++;
if(ex==0) break;
void main()
int i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
arr[i].fslno=random();
scanf("%s",arr[i].finfo);
sort();
}
Output:
Enter the number of frames
4
Enter the frame contents for sequence number 1804289383
write
Enter the frame contents for sequence number 846930886
do
Enter the frame contents for sequence number 1681692777
nw
Enter the frame contents for sequence number 1714636915
mute
The frames in sequence
846930886 do
1681692777 nw
1714636915 mute
1804289383 write
PROGRAM 10.
Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.
1. CLICK TO DOWNLOAD WIRESHARK
2. SETUP OF WIRESHARK
3.CHOOSE COMPONENTS
6. ADDITIONAL TASK
Packet Capture Using Wire shark
Home.html
<html>
<head>
<title>Home</title>
</head>
<frameset rows="25%,*">
<frame src="frame1.html">
<frameset cols="25%,*">
<frame src="frame2.html" name="f2">
<frame src="frame3.html" name="f3">
</frameset>
</html>
Frame1.html
<html>
<head><title>frame1</title>
</head>
<body bgcolor="blue">
<h1 style="color.green;font-size:15pt">
<marquee bgcolor="#cccccc" loop="-1" scrollamount="6" width="100%">
AURORA’S TECHNOLOGICAL AND RESEARCH INSTITUTE </marquee>
</h1>
</body>
</html>
Frame2.html
<html>
<head><title>frame2</title>
<style type="text/css">
h1
{
font-size:25pt;color:pink;
}
</style>
</head>
<body bgcolor="red">
<h1>click the link</h1>
<a href="intro.html" target=f3>Introduction</a><br>
<a href="dept.html" target=f3>Departments</a><br>
<a href="ad.html" target=f3>ADDRESS</a><br>
<a href="feed.html" target=f3>Feedback</a><br>
<a href="gall.html" target=f3>Gallery</a><br>
</body>
</html>
Frame3.html
<html>
<head><title>1st page</title>
<link rel="stylesheet" type="text/css" href="C:\Documents and
Settings\Administrator\Desktop\ab\css1.css"/>
</head>
<body bgcolor="tan">
<h2><center>YOU ARE IN HOME PAGE</center></h2>
</body>
</html>
Intro.html
<html>
<head><title>intro</title>
</head>
<body bgcolor="black">
<font color=red>
<p>
Welcome to AURORA’S TECHNOLOGICAL AND RESEARCH INSTITUTE <br>
<br>
“AURORA’S TECHNOLOGICAL AND RESEARCH INSTITUTE resolves to mould
a human task force useful to the society through transparent methods that
lead to continuous improvement of the resources and state-of-the-art
methodologies conforming to recognized standards.”
</p>
</font>
</body>
</html>
Ad.html
<html>
<head><title>ADDRESS</title>
</head>
<body bgcolor="black">
<p>
<font color=red>
Name:AURORA’S TECHNOLOGICAL AND RESEARCH INSTITUTE
Location:Hyderabad<br>
Contact No:040-29888909<br>
Website: www.atri.edu.in<br>
</font>
</p>
</body>
</html>
Dept.html
<html>
<head><title>Departments</title>
</head>
<body>
<div align="center">
<table border=2>
<tr>
<th>Dept code</th>
<th>Dept name</th>
</tr>
<tr>
<td>01</td>
<td>CSE</td>
</tr>
<tr>
<td>02</td>
<td>IT</td>
</tr>
<tr>
<td>03</td>
<td>EEE</td>
</tr>
<tr>
<td>04</td>
<td>IT</td>
</tr>
<tr>
<td>05</td>
<td>MECH</td>
</tr>
<tr>
<td>06</td>
<td>AI/ML</td>
</tr>
</table>
</div>
</body>
</html>
Feed.html
<html>
<head><title>feed</title>
</head>
<body bgcolor="black">
<p>
<font color=green>
To give your feedback mail to [email protected]
</font>
</p>
</body>
</html>
Gall.html
<html>
<head><title>gall</title>
</head>
<body bgcolor="pink">
<p>
<font color=blue>
College Front View</font>
</p>
<imgsrc="file:///d:/google.JPG" height="300" width="400"/>
</body>
</html>
OUTPUT:
PROGRAM 2:
Design a web site using HTML and DHTML. Use Basic text Formatting, Images
<html>
<head>
<body>
<center>
<script type = "text/Javascript"> var a = "Information";
document.write("<h2>" + a + "Technology" + "</h2>"); </script>
</center>
</body>
<title> Pseudo Classes for Hyperlinks </title><style type =
"text/css">a.col:link{color:blue} a.col:visited{color:black}
a.col:hover{color:orange}
a.big:link{color:skyblue}
a.big:visited{color:brown} a.big:hover{font-size:200%} </style>
</head>
<body>
<h3> Move the mouse over the text </h3><p>
<em>
<a class = "col" href = "form2.html" target = "_blank"> The text changes
the color</a></em>
</p>
<p>
<em>
<a class = "big" href = "form2.html" target = "_blank"> The
text is getting big in size </a>
</em>
</p>
</body>
</html>
Output:
PROGRAM 3:
Create a script that asks the user for a name, then greets the user with "Hello"
and the username on the page
<html>
<body>
<script>
</script>
</body>
</html>
Output:
Hello tom
PROGRAM 4:
Create a script that collects numbers from a page and then adds them up and
prints them to a blank field on the page
<html>
<body>
<div>
<div>
<h1>Add two number using text box as input using javascript</h1>
</div>
Enter First Number :<br>
<input type="text" id="Text1" name="TextBox1">
<br>
Enter Second Number :<br>
<input type="text" id="Text2" name="TextBox2">
<br>
Result :<br>
<input type="text" id="txtresult" name="TextBox3">
<br>
<input type="button" name="clickbtn" value="Display Result" onclick="add_number()">
<script type="text/javascript">
function add_number(){
var first_number = parseInt(document.getElementById("Text1").value);
var second_number = parseInt(document.getElementById("Text2").value);
var result = first_number + second_number;
document.getElementById("txtresult").innerHTML = result;
}
</script>
</html>
Output:
PROGRAM 5:
Create a script that prompts the user for a number and then counts from 1 to that
number displaying only the odd numbers
<html>
<body>
<h1>JS Find All Odd Numbers</h1>
<script>
var start = 10;
var end = 25;
<body>
<p> Click the following button to see the effect </p>
<form>
<input type = "button" value = "Click me" onclick = "fun();" />
</form>
</body>
</html>
Output:
PROGRAM 7:
<head>
<meta charset="UTF-8">
</head>
<body>
<nav>
<div class="menu">
<div class="logo">
<a href="#">CodingLab</a>
</div>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Feedback</a></li>
</ul>
</div>
</nav>
<div class="img"></div>
<div class="center">
<div class="title">Create Amazing Website</div>
<div class="btns">
<button>Learn More</button>
<button>Subscribe</button>
</div>
</div>
@import
url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins',sans-serif;
::selection{
color: #000;
background: #fff;
nav{
position: fixed;
background: #1b1b1b;
width: 100%;
padding: 10px 0;
z-index: 12;
nav .menu{
max-width: 1250px;
margin: auto;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20px;
.menu .logo a{
text-decoration: none;
color: #fff;
font-size: 35px;
font-weight: 600;
.menuul{
display: inline-flex;
.menuul li{
list-style: none;
margin-left: 7px;
.menuulli:first-child{
margin-left: 0px;
.menuul li a{
text-decoration: none;
color: #fff;
font-size: 18px;
font-weight: 500;
border-radius: 5px;
}
.menuul li a:hover{
background: #fff;
color: black;
.img{
background: url('img3.jpg')no-repeat;
width: 100%;
height: 100vh;
background-size: cover;
background-position: center;
position: relative;
.img::before{
content: '';
position: absolute;
height: 100%;
width: 100%;
.center{
position: absolute;
top: 52%;
left: 50%;
width: 100%;
padding: 0 20px;
text-align: center;
.center .title{
color: #fff;
font-size: 55px;
font-weight: 600;
.center .sub_title{
color: #fff;
font-size: 52px;
font-weight: 600;
.center .btns{
margin-top: 20px;
height: 55px;
width: 170px;
border-radius: 5px;
border: none;
margin: 0 10px;
font-size: 20px;
font-weight: 500;
padding: 0 10px;
cursor: pointer;
outline: none;
.center .btnsbutton:first-child{
color: #fff;
background: none;
}
.btnsbutton:first-child:hover{
background: white;
color: black;
.center .btnsbutton:last-child{
background: white;
color: black;
</body>
</html>
Output:
PROGRAM 8:
Creating simple application to access data base using JDBC Formatting HTML
with CSS
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
// Open a connection
<i>DATABASE STUDENTS</i>
stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
}
Output:
C:\>javac JDBCExample.java
C:\>
C:\>java JDBCExample
Database created successfully...
C:\>
PROGRAM 9:
//import statements...
DATABASE_URL = "jdbc:mysql://localhost/hr";
createTable(){
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,
USERNAME,
PASSWORD);
statement = connection.createStatement();
sqlEx.printStackTrace();
System.exit(1);
} catch (ClassNotFoundExceptionclsNotFoundEx) {
clsNotFoundEx.printStackTrace();
System.exit(1); } finally {
public static void createEmployee(int id, String name, int dept, int
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,
USERNAME,PASSWORD);
preparedStatement = connection.prepareStatement("INSERT
b=preparedStatement.execute(); if(b==true)
System.exit(1);
} catch (ClassNotFoundExceptionclsNotFoundEx) {
clsNotFoundEx.printStackTrace();
System.exit(1); } finally {
try {
preparedStatement.close();
connection.close();
try {
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,
USERNAME,PASSWORD);
preparedStatement = connection.prepareStatement("UPDATE
System.exit(1);
} catch (ClassNotFoundExceptionclsNotFoundEx) {
clsNotFoundEx.printStackTrace();
System.exit(1); } finally {
}
}
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,
USERNAME,PASSWORD);
preparedStatement = connection.prepareStatement("DELETE
preparedStatement.setInt(1, id)
System.exit(1);
} catch (ClassNotFoundExceptionclsNotFoundEx) {
clsNotFoundEx.printStackTrace();
System.exit(1); } finally {
}}}
try { Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,
USERNAME,
PASSWORD);
statement = connection.createStatement();
if (i != 3) System.out.printf("%-10s\t",
metaData.getColumnName(i).toUpperCase());
System.out.printf("%-10s\t", resultSet.getObject(i));
System.out.println();
System.exit(1);
} catch (ClassNotFoundExceptionclsNotFoundEx) {
clsNotFoundEx.printStackTrace();
System.exit(1);
} finally { try {
statement.close();
connection.close();
}
}
try { Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,
USERNAME,
PASSWORD);
statement = connection.createStatement();
ResultSetresultSet = statement.executeQuery("SELECT *
metaData.getColumnCount();
10s\t",
metaData.getColumnName(i).toUpperCase());
System.out.println();
while (resultSet.next()) {
System.out.printf("%-10s\t", resultSet.getObject(i));
System.out.println();
System.exit(1);
} catch (ClassNotFoundExceptionclsNotFoundEx) {
clsNotFoundEx.printStackTrace();
System.exit(1);
} finally { try {
statement.close();
connection.close();
Index.html
<html>
<body>
<form action="insert.php" method="post">
<center><h1>PHP-OPEN SOURCE ENVIRONMENT</h1></center>
<center><b>Firstname:</b><input type="text" name="firstname"
/><br><br>
<b>Lastname:</b><input type="text" name="lastname"
/><br><br>
<b>Age:</b><input type="text" name="age" /><br><br>
<input type="submit" /></center>
</form>
</body>
</html>
Insert.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sample", $con);
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<h1>1 record added";
mysql_close($con)
?>
Output:
PROGRAM 11:
Program using PHP database functions
<?PHP
?>
$db_found = mysql_select_db($database); if ($db_found) {
print "Database Found";
}
else {
print "Database NOT Found";
<?PHP
if ($db_found) {
print "Database Found "; mysql_close($db_handle);
}
else {
print "Database NOT Found ";
?>
Output:
Write a web application that functions as a simple hand calculator, but also keeps
a "paper trail" of all your previous work
Program code:
Html code:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Simple Calculator using HTML, CSS and JavaScript</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
</body>
</html>
CSS code:
@import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap');
.calculator {
padding: 10px;
border-radius: 1em;
height: 380px;
width: 400px;
margin: auto;
background-color: #191b28;
box-shadow: rgba(0, 0, 0, 0.19) 0px 10px 20px, rgba(0, 0, 0, 0.23) 0px 6px 6px;
}
.display-box {
font-family: 'Orbitron', sans-serif;
background-color: #dcdbe1;
border: solid black 0.5px;
color: black;
border-radius: 5px;
width: 100%;
height: 65%;
}
#btn {
background-color: #fb0066;
}
input[type=button] {
font-family: 'Orbitron', sans-serif;
background-color: #64278f;
color: white;
border: solid black 0.5px;
width: 100%;
border-radius: 5px;
height: 70%;
outline: none;
}
input:active[type=button] {
background: #e5e5e5;
-webkit-box-shadow: inset 0px 0px 5px #c1c1c1;
-moz-box-shadow: inset 0px 0px 5px #c1c1c1;
box-shadow: inset 0px 0px 5px #c1c1c1;
}
JAVASCRIPT code:
function clearScreen() {
document.getElementById("result").value = "";
}
MONITOR TOMCAT
8 . It will show tomcat, as shown in above window. (if not, then try
again, may be a problem in installation or you?e not following above
steps correctly
web-apps
10 . Open web-apps and ?opy your projector ?ake new folder which
you want to run in JSP. Example: amit2012PROJECT Now, goback :
Tomcat Root
11 . Create a text file and name it as first.jsp, use the code shownbelow:
<html>
<head>
<title>blog post:ApacheTomcatServer</title>
</head>
<body>
<%
</body>
</html>
It includes HTML tags and encloses a JSP scriptlet which is a fragment of Java
code that is run when the user requests the page.
using System;
using System.Web;
using System.Web.Services;
namespace calc
[WebService(Namespace = "mycalculatorexample.org")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[WebMethod]
case '+':
{
result = (Convert.ToInt32(first) + Convert.ToInt32(second)).ToString();
break;
case '-':
case '*':
case '/':
case '%':
{
result = (Convert.ToInt32(first) % Convert.ToInt32(second)).ToString(); break;
default:
}
return result;
}
Output:
Thus the implementation of web service for calculator
applicationexecuted successfully.
PROGRAM 15:
1. import java.rmi.*;
2. import java.rmi.server.*;
3. public class AdderRemote extends UnicastRemoteObject implements Adder{
4. AdderRemote()throws RemoteException{
5. super();
6. }
7. public int add(int x,int y){return x+y;}
8. }
3) create the stub and skeleton objects using the rmic tool.
1. rmic AdderRemote
rmiregistry 5000
5) Create and run the server application
public static java.rmi.Remote lookup(java.lang.String) throws
java.rmi.NotBoundException, java.net.MalformedURLException,
java.rmi.RemoteException;
Remote object by the name sonoo
1. import java.rmi.*;
2. import java.rmi.registry.*;
3. public class MyServer{
4. public static void main(String args[]){
5. try{
6. Adder stub=new AdderRemote();
7. Naming.rebind("rmi://localhost:5000/sonoo",stub);
8. }catch(Exception e){System.out.println(e);}
9. }
10. }