System Software Viva Questions :
Download from Here ......
Anna University Results November - December 2011 available with your GPA only for Credit System
Anna University Results Nov - Dec 2011
Exam Results 2012
Exam Results 2012 | Inspirational Quotes |
Showing posts with label CSE - V SEM. Show all posts
Showing posts with label CSE - V SEM. Show all posts
Saturday, October 23, 2010
Tuesday, October 12, 2010
Network Lab Programs - CS2307
Network Lab Programs - CS2307 :
1)a).Implementation of Socket Programming Using TCP
1)b).Implementation of Echo Server and Client Using TCP
1)c).Implementation of Remote Command Execution using TCP
1)d).Implementation of Talk Using TCP
2).Implementation of Socket Programming Using UDP
3).Implementation of PING Server Using Raw Socket
4).Implementation of Remote Method Invocation ( RMI )
5).Implementation of Simulation of Sliding Window Protocol
6)a).Implementation of Distance Vector Routing
6)b).Implementation of Shortest Path Computation in OSPF (Dijikstra’s Algorithm)
7).OPNET - Shared Ethernet Networks
8).OPNET - Routing Protocols
9).OPNET - TCP Throughput
10).OPNET - TCP versus UDP Response Time
Required Software :
OPNET - Download from here .....
More Programs Coming Soon .....
1)a).Implementation of Socket Programming Using TCP
1)b).Implementation of Echo Server and Client Using TCP
1)c).Implementation of Remote Command Execution using TCP
1)d).Implementation of Talk Using TCP
2).Implementation of Socket Programming Using UDP
3).Implementation of PING Server Using Raw Socket
4).Implementation of Remote Method Invocation ( RMI )
5).Implementation of Simulation of Sliding Window Protocol
6)a).Implementation of Distance Vector Routing
6)b).Implementation of Shortest Path Computation in OSPF (Dijikstra’s Algorithm)
7).OPNET - Shared Ethernet Networks
8).OPNET - Routing Protocols
9).OPNET - TCP Throughput
10).OPNET - TCP versus UDP Response Time
Required Software :
OPNET - Download from here .....
More Programs Coming Soon .....
Labels:
CSE - V SEM,
Page Titles - V SEM
Sunday, October 10, 2010
System Software Lab Programs - CS2308
System Software Lab Programs - CS2308 :
1.Single Pass Macro Processor
More Programs Coming Soon .....
1.Single Pass Macro Processor
More Programs Coming Soon .....
Labels:
CSE - V SEM,
Page Titles - V SEM
Java Lab Programs - CS2309
Java Lab Programs - CS2309 :
1.Object Serialization in Java
2.Multi-Thread Using Pipe in Java Program
3.Muti-Threaded Echo Server and Corresponding GUI Client in Java
4.OPAC Library Management System
More Programs Coming Soon .....
1.Object Serialization in Java
2.Multi-Thread Using Pipe in Java Program
3.Muti-Threaded Echo Server and Corresponding GUI Client in Java
4.OPAC Library Management System
More Programs Coming Soon .....
Labels:
CSE - V SEM,
Page Titles - V SEM
Wednesday, October 6, 2010
Lab Programs - CSE - V SEM
Lab Programs - CSE - V SEM :
(As per Anna University Syllabus - Regulation 2008)
1.Network Lab Programs - CS2307
2.System Software Lab Programs - CS2308
3.Java Lab Programs - CS2309
(As per Anna University Syllabus - Regulation 2008)
1.Network Lab Programs - CS2307
2.System Software Lab Programs - CS2308
3.Java Lab Programs - CS2309
Labels:
CSE - V SEM,
Page Titles - V SEM
Thursday, September 30, 2010
OPAC Library Management System program in Java
OPAC Library Management System program in Java :
Develop a simple OPAC system for library using even-driven and concurrent programming paradigms of Java. Use JDBC to connect to a back-end database.
Procedure :
Now execute the following code “Library.java”.
Library.java
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class Library implements ActionListener
{
JRadioButton rbauthor = new JRadioButton("Search by Author name");
JRadioButton rbbook = new JRadioButton("Search by Book name");
JTextField textfld = new JTextField(30);
JLabel label = new JLabel("Enter Search Key");
JButton searchbutton = new JButton("Search");
JFrame frame = new JFrame();
JTable table;
DefaultTableModel model;
String query = "select * from Library";
public Library()
{
frame.setTitle("Online Public Access Catalog");
frame.setSize(500,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(label);
p1.add(textfld);
ButtonGroup bg = new ButtonGroup();
bg.add(rbauthor);
bg.add(rbbook);
p2.setLayout(new FlowLayout());
p2.add(rbauthor);
p2.add(rbbook);
p2.add(searchbutton);
searchbutton.addActionListener(this);
p3.setLayout(new BorderLayout());
p3.add(p1,BorderLayout.NORTH);
p3.add(p2,BorderLayout.CENTER);
frame.add(p3,BorderLayout.NORTH);
addTable(query);
frame.setVisible(true);
}
public void addTable(String s)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:Library","","");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(s);
ResultSetMetaData md = rs.getMetaData();
int cols = md.getColumnCount();
model = new DefaultTableModel(1,cols);
table = new JTable(model);
String[] tabledata = new String[cols];
int i=0;
while(i<cols)
{
tabledata[i] = md.getColumnName(i+1);
i++;
}
model.addRow(tabledata);
while(rs.next())
{
for(i=0;i<cols;i++)
tabledata[i] = rs.getObject(i+1).toString();
model.addRow(tabledata);
}
frame.add(table,BorderLayout.CENTER);
conn.close();
}catch(Exception e){}
}
public void actionPerformed(ActionEvent evt)
{
if(rbauthor.isSelected())
query = "select * from Library where AuthorName like '"+textfld.getText()+"%'";
if(rbbook.isSelected())
query = "select * from Library where BookName like '"+textfld.getText()+"%'";
while(model.getRowCount()>0)
model.removeRow(0);
frame.remove(table);
addTable(query);
}
public static void main(String[] args)
{
new Library();
}
}
Screenshots of Output :
(Opening Screen)
(author Search)
(Book Search)
Download the Source Code
Library.java
books.mdb
Develop a simple OPAC system for library using even-driven and concurrent programming paradigms of Java. Use JDBC to connect to a back-end database.
Procedure :
- Create a new Database file in MS ACCESS (our backend) named “books.mdb”.
- Then create a table named “Library” in it.
- The table Library contains the following fields and data types,
- AuthorName – Text
- ISBN – Text
- BookName - Text
- Price - Number
- Publisher – Text
- Enter various records as you wish.
- Save the database file.
- Next step is to add our “books.mdb” to the System DSN. To do that follow the procedure given below,
- Go to Start-> Control Panel -> Administrative tools.
- In that double click “Data Sources (ODBC)”.
- ODBC Data Source Administrator dialog appears.
- In that select “System DSN” tab and click the Add Button.
- Select “Microsoft Access Driver(*.mdb)” and click Finish.
- ODBC Microsoft Access Setup appears. In the “Data Source name” type “Library”.
- Click on the “Select” button and choose your database file. Then click ok.
Now your database file gets added to the System DSN. It should look like below,
Now execute the following code “Library.java”.
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class Library implements ActionListener
{
JRadioButton rbauthor = new JRadioButton("Search by Author name");
JRadioButton rbbook = new JRadioButton("Search by Book name");
JTextField textfld = new JTextField(30);
JLabel label = new JLabel("Enter Search Key");
JButton searchbutton = new JButton("Search");
JFrame frame = new JFrame();
JTable table;
DefaultTableModel model;
String query = "select * from Library";
public Library()
{
frame.setTitle("Online Public Access Catalog");
frame.setSize(500,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(label);
p1.add(textfld);
ButtonGroup bg = new ButtonGroup();
bg.add(rbauthor);
bg.add(rbbook);
p2.setLayout(new FlowLayout());
p2.add(rbauthor);
p2.add(rbbook);
p2.add(searchbutton);
searchbutton.addActionListener(this);
p3.setLayout(new BorderLayout());
p3.add(p1,BorderLayout.NORTH);
p3.add(p2,BorderLayout.CENTER);
frame.add(p3,BorderLayout.NORTH);
addTable(query);
frame.setVisible(true);
}
public void addTable(String s)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:Library","","");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(s);
ResultSetMetaData md = rs.getMetaData();
int cols = md.getColumnCount();
model = new DefaultTableModel(1,cols);
table = new JTable(model);
String[] tabledata = new String[cols];
int i=0;
while(i<cols)
{
tabledata[i] = md.getColumnName(i+1);
i++;
}
model.addRow(tabledata);
while(rs.next())
{
for(i=0;i<cols;i++)
tabledata[i] = rs.getObject(i+1).toString();
model.addRow(tabledata);
}
frame.add(table,BorderLayout.CENTER);
conn.close();
}catch(Exception e){}
}
public void actionPerformed(ActionEvent evt)
{
if(rbauthor.isSelected())
query = "select * from Library where AuthorName like '"+textfld.getText()+"%'";
if(rbbook.isSelected())
query = "select * from Library where BookName like '"+textfld.getText()+"%'";
while(model.getRowCount()>0)
model.removeRow(0);
frame.remove(table);
addTable(query);
}
public static void main(String[] args)
{
new Library();
}
}
Screenshots of Output :
(Opening Screen)

(author Search)


Download the Source Code
Library.java
books.mdb
Labels:
CSE - V SEM,
Java Lab Programs - CS2309
OPNET Download ......
OPNET Download :
procedure to install...........
click here to download the user guide...........(must download)
Labels:
CSE - V SEM,
OPNET Download
Saturday, September 25, 2010
Muti-Threaded Echo Server and Corresponding GUI Client in Java
/* Muti-Threaded Echo Server and Corresponding GUI Client in Java */
// EchoServer.java
import java.net.*; import java.io.*;
public class EchoServer
{
ServerSocket ss;
public EchoServer()
{
try
{
ss = new ServerSocket(12111);
}
catch(Exception e)
{
System.out.println("Error ... " + e.getMessage());
System.exit(-1);
}
System.out.println("Listening for clients.....");
int id = 0;
while(true)
{
try
{
Socket cs = ss.accept();
ClientServiceThread ct = new ClientServiceThread(cs, id++);
ct.start();
}
catch(Exception e)
{
System.out.println(" Error " + e.getMessage());
System.exit(-1);
}
}
}
public static void main (String[] args)
{
new EchoServer();
}
class ClientServiceThread extends Thread
{
Socket cs;
int m_clientID = -1;
boolean m_bRunThread = true;
ClientServiceThread(Socket s, int clientID)
{
cs = s;
m_clientID = clientID;
}
public void run()
{
BufferedReader in = null;
PrintWriter out = null;
System.out.println("Accepted Client : ID - " + m_clientID + " : Address - " + cs.getInetAddress().getHostName());
try
{
in = new BufferedReader(new InputStreamReader(cs.getInputStream()));
out = new PrintWriter(new OutputStreamWriter(cs.getOutputStream()));
while(m_bRunThread)
{
String clientCommand = in.readLine();
System.out.println("Client Says :" + clientCommand);
if(clientCommand.equalsIgnoreCase("exit"))
{
m_bRunThread = false;
System.out.print("Stopping client thread for client : " + m_clientID);
System.exit(-1);
}
else
{
out.println(clientCommand);
out.flush();
}
}
in.close();
out.close();
cs.close();
System.out.println("...Stopped");
}
catch(Exception e)
{
System.exit(-1);
}
}
}
}
// EchoClient.java
import java.net.*;
import java.io.*;
public class EchoClient
{
public static void main(String args[])
{
Socket s = null;
try
{
s = new Socket("localhost", 12111);
}
catch( Exception e)
{
System.out.println("Error ... " + e.getMessage());
System.exit(-1);
}
if(s == null)
System.exit(-1);
BufferedReader in = null;
PrintWriter out = null;
try
{
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
out = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String msg;
while(true)
{
System.out.print(" Enter the Message : " );
msg=br.readLine();
if(msg.compareTo("exit")==0)
{
out.println(msg);
out.flush();
break;
}
out.println(msg);
out.flush();
System.out.println(" Server Says : " + in.readLine());
}
out.close();
in.close();
s.close();
}
catch(Exception e)
{
System.out.println("Error ... " + e.getMessage());
System.exit(-1);
}
}
}
OUTPUT :
// EchoServer.java
javac EchoServer.java
java EchoServer
Listening for clients.....
Accepted Client : ID - 0 : Address - localhost
Client Says :Welcome To JCE
Client Says :I am Baran
Client Says :CSE Rocks .....
Client Says :exit
Stopping client thread for client : 0
// EchoClient.java
javac EchoClient.java
java EchoClient
Enter the Message : Welcome To JCE
Server Says : Welcome To JCE
Enter the Message : I am Baran
Server Says : I am Baran
Enter the Message : CSE Rocks .....
Server Says : CSE Rocks .....
Enter the Message : exit
If u find any flaws , Contact to M.Baran Mahamood
Labels:
CSE - V SEM,
Java Lab Programs - CS2309
Object Serialization in Java
/* SerializationWrite.java */
import java.io.*;
import java.util.*;
class Currency implements Serializable
{
protected String currency;
protected int amount;
public Currency(String cur, int amt)
{
this.currency = cur;
this.amount = amt;
}
public String toString()
{
return currency + amount;
}
public String dollarToRupee(int amt)
{
return "Rs" + amt * 45;
}
}
class Rupee extends Currency
{
public Rupee(int amt)
{
super("Rs",amt);
}
}
class Dollar extends Currency
{
public Dollar(int amt)
{
super("$",amt);
}
}
public class SerializationWrite
{
public static void main(String args[])
{
Random r = new Random();
try
{
Currency currency;
FileOutputStream fos = new FileOutputStream("serial.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
System.out.println("Writing to file using Object Serialization:");
for(int i=1;i<=25;i++)
{
Object[] obj = { new Rupee(r.nextInt(5000)),new Dollar(r.nextInt(5000)) };
currency = (Currency)obj[r.nextInt(2)]; // RANDOM Objects for Rs and $
System.out.println(currency);
oos.writeObject(currency);
oos.flush();
}
oos.close();
}
catch(Exception e)
{
System.out.println("Exception during Serialization: " + e);
}
}
}
OUTPUT :
Writing to file using Object Serialization:
Rs2337
Rs1629
$339
Rs1092
Rs1193
$1957
Rs1450
$1799
$1497
$4586
Rs1650
Rs88
Rs1862
$4392
$4216
Rs4722
import java.util.*;
class Currency implements Serializable
{
protected String currency;
protected int amount;
public Currency(String cur, int amt)
{
this.currency = cur;
this.amount = amt;
}
public String toString()
{
return currency + amount;
}
public String dollarToRupee(int amt)
{
return "Rs" + amt * 45;
}
}
class Rupee extends Currency
{
public Rupee(int amt)
{
super("Rs",amt);
}
}
class Dollar extends Currency
{
public Dollar(int amt)
{
super("$",amt);
}
}
public class SerializationWrite
{
public static void main(String args[])
{
Random r = new Random();
try
{
Currency currency;
FileOutputStream fos = new FileOutputStream("serial.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
System.out.println("Writing to file using Object Serialization:");
for(int i=1;i<=25;i++)
{
Object[] obj = { new Rupee(r.nextInt(5000)),new Dollar(r.nextInt(5000)) };
currency = (Currency)obj[r.nextInt(2)]; // RANDOM Objects for Rs and $
System.out.println(currency);
oos.writeObject(currency);
oos.flush();
}
oos.close();
}
catch(Exception e)
{
System.out.println("Exception during Serialization: " + e);
}
}
}
OUTPUT :
Writing to file using Object Serialization:
Rs2337
Rs1629
$339
Rs1092
Rs1193
$1957
Rs1450
$1799
$1497
$4586
Rs1650
Rs88
Rs1862
$4392
$4216
Rs4722
Rs676
Rs3159
$409
$1093
Rs2751
Rs2299
Rs1595
$4650
Rs2126
Rs3159
$409
$1093
Rs2751
Rs2299
Rs1595
$4650
Rs2126
/* SerializationRead.java */
import java.util.*;
public class SerializationRead
{
public static void main(String args[])
{
try
{
Currency obj;
FileInputStream fis = new FileInputStream("serial.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
System.out.println("Reading from file using Object Serialization:");
for(int i=1;i<=25;i++)
{
obj = (Currency)ois.readObject();
if((obj.currency).equals("$"))
System.out.println(obj + " = " + obj.dollarToRupee(obj.amount));
else
System.out.println(obj + " = " + obj);
}
ois.close();
}
catch(Exception e)
{
System.out.println("Exception during deserialization." + e);
}
}
}
OUTPUT :
Reading from file using Object Serialization:
Rs2337 = Rs2337
Rs1629 = Rs1629
$339 = Rs15255
Rs1092 = Rs1092
Rs1193 = Rs1193
$1957 = Rs88065
Rs1450 = Rs1450
$1799 = Rs80955
$1497 = Rs67365
$4586 = Rs206370
Rs1650 = Rs1650
Rs88 = Rs88
Rs1862 = Rs1862
$4392 = Rs197640
$4216 = Rs189720
Rs4722 = Rs4722
Rs676 = Rs676
Rs3159 = Rs3159
$409 = Rs18405
$1093 = Rs49185
Rs2751 = Rs2751
Rs2299 = Rs2299
Rs1595 = Rs1595
$4650 = Rs209250
Rs2126 = Rs2126
If u find any flaws , Contact to M.Baran Mahamood
Labels:
CSE - V SEM,
Java Lab Programs - CS2309
Multi Thread Using Pipe in Java Program
/* Multi Thread Using Pipe in Java Program */
import java.util.*;
import java.io.*;
class Fibonacci extends Thread
{
private PipedWriter out = new PipedWriter();
public PipedWriter getPipedWriter()
{
return out;
}
public void run()
{
Thread t = Thread.currentThread();
t.setName("Fibonacci");
System.out.println(t.getName() + " thread started");
int fibo1=0,fibo2=1,fibo=0;
while(true)
{
try
{
fibo = fibo1 + fibo2;
if(fibo>100000)
{
out.close();
break;
}
out.write(fibo);
sleep(1000);
}
catch(Exception e)
{
System.out.println("Fibonacci:"+e);
}
fibo1=fibo2;
fibo2=fibo;
}
System.out.println(t.getName() + " thread exiting");
}
}
class Prime extends Thread
{
private PipedWriter out1 = new PipedWriter();
public PipedWriter getPipedWriter()
{
return out1;
}
public void run()
{
Thread t= Thread.currentThread();
t.setName("Prime");
System.out.println(t.getName() + " thread Started...");
int prime=1;
while(true)
{
try
{
if(prime>100000)
{
out1.close();
break;
}
if(isPrime(prime))
out1.write(prime);
prime++;
sleep(0);
}
catch(Exception e)
{
System.out.println(t.getName() + " thread exiting.");
System.exit(0);
}
}
}
public boolean isPrime(int n)
{
int m=(int)Math.round(Math.sqrt(n));
if(n==1 || n==2)
return true;
for(int i=2;i<=m;i++)
if(n%i==0)
return false;
return true;
}
}
public class PipedIo
{
public static void main(String[] args) throws Exception
{
Thread t=Thread.currentThread();
t.setName("Main");
System.out.println(t.getName() + " thread Started...");
Fibonacci fibonacci = new Fibonacci();
Prime prime = new Prime();
PipedReader fpr = new PipedReader(fibonacci.getPipedWriter());
PipedReader ppr = new PipedReader(prime.getPipedWriter());
fibonacci.start();
prime.start();
int fib=fpr.read(), prm=ppr.read();
System.out.println("The numbers common to PRIME and FIBONACCI:");
while((fib!=-1) && (prm!=-1))
{
while(prm<=fib)
{
if(fib==prm)
System.out.println(prm);
prm=ppr.read();
}
fib=fpr.read();
}
System.out.println(t.getName() + " thread exiting");
}
}
OUTPUT :import java.io.*;
class Fibonacci extends Thread
{
private PipedWriter out = new PipedWriter();
public PipedWriter getPipedWriter()
{
return out;
}
public void run()
{
Thread t = Thread.currentThread();
t.setName("Fibonacci");
System.out.println(t.getName() + " thread started");
int fibo1=0,fibo2=1,fibo=0;
while(true)
{
try
{
fibo = fibo1 + fibo2;
if(fibo>100000)
{
out.close();
break;
}
out.write(fibo);
sleep(1000);
}
catch(Exception e)
{
System.out.println("Fibonacci:"+e);
}
fibo1=fibo2;
fibo2=fibo;
}
System.out.println(t.getName() + " thread exiting");
}
}
class Prime extends Thread
{
private PipedWriter out1 = new PipedWriter();
public PipedWriter getPipedWriter()
{
return out1;
}
public void run()
{
Thread t= Thread.currentThread();
t.setName("Prime");
System.out.println(t.getName() + " thread Started...");
int prime=1;
while(true)
{
try
{
if(prime>100000)
{
out1.close();
break;
}
if(isPrime(prime))
out1.write(prime);
prime++;
sleep(0);
}
catch(Exception e)
{
System.out.println(t.getName() + " thread exiting.");
System.exit(0);
}
}
}
public boolean isPrime(int n)
{
int m=(int)Math.round(Math.sqrt(n));
if(n==1 || n==2)
return true;
for(int i=2;i<=m;i++)
if(n%i==0)
return false;
return true;
}
}
public class PipedIo
{
public static void main(String[] args) throws Exception
{
Thread t=Thread.currentThread();
t.setName("Main");
System.out.println(t.getName() + " thread Started...");
Fibonacci fibonacci = new Fibonacci();
Prime prime = new Prime();
PipedReader fpr = new PipedReader(fibonacci.getPipedWriter());
PipedReader ppr = new PipedReader(prime.getPipedWriter());
fibonacci.start();
prime.start();
int fib=fpr.read(), prm=ppr.read();
System.out.println("The numbers common to PRIME and FIBONACCI:");
while((fib!=-1) && (prm!=-1))
{
while(prm<=fib)
{
if(fib==prm)
System.out.println(prm);
prm=ppr.read();
}
fib=fpr.read();
}
System.out.println(t.getName() + " thread exiting");
}
}
Main thread Started...
Fibonacci thread started
Prime thread Started...
The numbers common to PRIME and FIBONACCI:
1
2
3
5
13
89
233
1597
28657
Fibonacci thread exiting
Main thread exiting
Prime thread exiting.
If u find any flaws, Contact to M.Baran Mahamood
Labels:
CSE - V SEM,
Java Lab Programs - CS2309
Saturday, September 18, 2010
Implementation of Shortest Path Computation in OSPF (Dijikstra’s Algorithm)
/* Implementation of Shortest Path Computation in OSPF (Dijikstra’s Algorithm) */
#include<stdio.h>
main()
{
int i,j,k,n,a[10][10],b[10][10];
printf("\n Enter the no.of nodes : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\n Enter the distance between the host %d to %d : ",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("\n The given Matrix is : \n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf(" %d\t",a[i][j]);
}
printf("\n");
}
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(a[i][j]>a[i][k]+a[k][j])
a[i][j]=a[i][k]+a[k][j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=a[i][j];
if(i==j)
b[i][j]=0;
}
}
printf("\n The output Matrix is : \n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf(" %d \t",b[i][j]);
}
printf("\n");
}
}
OUTPUT :
Enter the no.of nodes : 4
Enter the distance between the host 1 to 1 : 0
Enter the distance between the host 1 to 2 : 2
Enter the distance between the host 1 to 3 : 5
Enter the distance between the host 1 to 4 : 3
Enter the distance between the host 2 to 1 : 2
Enter the distance between the host 2 to 2 : 0
Enter the distance between the host 2 to 3 : 6
Enter the distance between the host 2 to 4 : 1
Enter the distance between the host 3 to 1 : 3
Enter the distance between the host 3 to 2 : 1
Enter the distance between the host 3 to 3 : 0
Enter the distance between the host 3 to 4 : 6
Enter the distance between the host 4 to 1 : 3
Enter the distance between the host 4 to 2 : 1
Enter the distance between the host 4 to 3 : 5
Enter the distance between the host 4 to 4 : 0
The given Matrix is :
0 2 5 3
2 0 6 1
3 1 0 6
3 1 5 0
The output Matrix is :
0 2 5 3
2 0 6 1
3 1 0 2
3 1 5 0
Labels:
CSE - V SEM,
Network Lab Programs - CS2307
Simulation of Sliding Window Protocol
/* Simulation of Sliding Window Protocol */
// SlideServer.c : A Simple Slide Server Program Using Sliding Window Protocol
#include<stdio.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
#include<stdlib.h>
#include<arpa/inet.h>
#define SIZE 4
int main()
{
int sfd,lfd,len,i,j,status;
char str[20],frame[20],temp[20],ack[20];
struct sockaddr_in saddr,caddr;
sfd=socket(AF_INET,SOCK_STREAM,0);
if(sfd<0)
perror("Error");
bzero(&saddr,sizeof(saddr));
saddr.sin_family=AF_INET;
saddr.sin_addr.s_addr=htonl(INADDR_ANY);
saddr.sin_port=htons(5465);
if(bind(sfd,(struct sockaddr*)&saddr,sizeof(saddr))<0)
perror("Bind Error");
listen(sfd,5);
len=sizeof(&caddr);
lfd=accept(sfd,(struct sockaddr*)&caddr,&len);
printf(" Enter the text : \n");
scanf("%s",str);
i=0;
while(i<strlen(str))
{
memset(frame,0,20);
strncpy(frame,str+i,SIZE);
printf(" Transmitting Frames. ");
len=strlen(frame);
for(j=0;j<len;j++)
{
printf("%d",i+j);
sprintf(temp,"%d",i+j);
strcat(frame,temp);
}
printf("\n");
write(lfd,frame,sizeof(frame));
read(lfd,ack,20);
sscanf(ack,"%d",&status);
if(status==-1)
printf(" Transmission is successful. \n");
else
{
printf(" Received error in %d \n\n",status);
printf("\n\n Retransmitting Frame. ");
for(j=0;;)
{
frame[j]=str[j+status];
printf("%d",j+status);
j++;
if((j+status)%4==0)
break;
}
printf("\n");
frame[j]='\0';
len=strlen(frame);
for(j=0;j<len;j++)
{
sprintf(temp,"%d",j+status);
strcat(frame,temp);
}
write(lfd,frame,sizeof(frame));
}
i+=SIZE;
}
write(lfd,"exit",sizeof("exit"));
printf("Exiting\n");
sleep(2);
close(lfd);
close(sfd);
}
// SlideClient.c : A Simple Slide Client Program Using Sliding Window Protocol
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
int main()
{
int sfd,lfd,len,choice;
char str[20],str1[20],err[20];
struct sockaddr_in saddr,caddr;
sfd=socket(AF_INET,SOCK_STREAM,0);
if(sfd<0)
perror("FdError");
bzero(&saddr,sizeof(saddr));
saddr.sin_family=AF_INET;
saddr.sin_addr.s_addr=INADDR_ANY;
saddr.sin_port=htons(5465);
connect(sfd,(struct sockaddr*)&saddr,sizeof(saddr));
for(;;)
{
read(sfd,str,20);
if(!strcmp(str,"exit"))
{
printf("Exiting\n");
break;
}
printf("\n\nReceived%s\n\n1.Do u want to report an error(1-Yes 0-No)",str);
scanf("%d",&choice);
if(!choice)
write(sfd,"-1",sizeof("-1"));
else
{
printf("Enter the sequence no of the frame where error has occured\n");
scanf("%s",err);
write(sfd,err,sizeof(err));
read(sfd,str,20);
printf("\n\nReceived the re-transmitted frames%s\n\n",str);
}
}
}
OUT PUT :
SlideServer.c :
cc SlideServer.c
./a.out
Enter the text
jerusalem
Transmitting Frames=0123
Transmission is successful
Transmitting Frames=4567
Received error in 5
Retransmitting Frame=678
Transmitting Frames=8
Received error in 2
Retransmitting Frame=34
Exiting
ClientServer.c :
cc ClientServer.c
./a.out
Received=jeru0123
1.Do u want to report an error(1-Yes 0-No)0
Received=sale4567
1.Do u want to report an error(1-Yes 0-No)1
Enter the sequence no of the frame where error has occured
5
Received the re-transmitted frames=ale567
Received=m8
1.Do u want to report an error(1-Yes 0-No)1
Enter the sequence no of the frame where error has occured
2
Received the re-transmitted frames=ru23
Exiting
Labels:
CSE - V SEM,
Network Lab Programs - CS2307
Implementation of Distance Vector Routing
/* Implementation of Distance Vector Routing */
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
int i,j,k,n,a[10][10],b[10][10],src,s,d;
char ch;
clrscr();
printf("\n Enter the number of nodes = ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==j)
a[i][j]=0;
else
{
printf("\n Enter the distance between host : %d and %d ==> ",i,j);
scanf("%d",&a[i][j]);
}
}
}
printf("\n ");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d\t",a[i][j]);
printf("\n ");
}
do
{
printf("\n Enter the node to display the routing table : ");
scanf("%d",&src);
for(j=1;j<=n;j++)
{
if(src!=j)
{
if(a[src][j]!=0)
printf("\n The shortest path from %d to %d = %d \n",src,j,a[src][j]);
else
printf("\n There is no path from %d to %d \n",src,j);
}
}
printf("\n Do u want to continue(y/n) : ");
scanf("%s",&ch);
}while(ch!='n');
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(a[i][j]>a[i][k]+a[k][j])
a[i][j]=a[i][k]+a[k][j];
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
getch();
}
OUT PUT :
SHOWS A SUBNET

Enter the number of nodes = 6
Enter the distance between host : 1 and 2 ==> 2
Enter the distance between host : 1 and 3 ==> 5
Enter the distance between host : 1 and 4 ==> 1
Enter the distance between host : 1 and 5 ==> 2
Enter the distance between host : 1 and 6 ==> 10
Enter the distance between host : 2 and 1 ==> 2
Enter the distance between host : 2 and 3 ==> 3
Enter the distance between host : 2 and 4 ==> 2
Enter the distance between host : 2 and 5 ==> 3
Enter the distance between host : 2 and 6 ==> 8
Enter the distance between host : 3 and 1 ==> 5
Enter the distance between host : 3 and 2 ==> 3
Enter the distance between host : 3 and 4 ==> 3
Enter the distance between host : 3 and 5 ==> 1
Enter the distance between host : 3 and 6 ==> 5
Enter the distance between host : 4 and 1 ==> 1
Enter the distance between host : 4 and 2 ==> 2
Enter the distance between host : 4 and 3 ==> 3
Enter the distance between host : 4 and 5 ==> 1
Enter the distance between host : 4 and 6 ==> 3
Enter the distance between host : 5 and 1 ==> 6
Enter the distance between host : 5 and 2 ==> 4
Enter the distance between host : 5 and 3 ==> 1
Enter the distance between host : 5 and 4 ==> 1
Enter the distance between host : 5 and 6 ==> 2
Enter the distance between host : 6 and 1 ==> 10
Enter the distance between host : 6 and 2 ==> 8
Enter the distance between host : 6 and 3 ==> 5
Enter the distance between host : 6 and 4 ==> 3
Enter the distance between host : 6 and 5 ==> 2
ROUTING TABLE :
| 1 | 2 | 3 | 4 | 5 | 6 |
1 | 0 | 2 | 5 | 1 | 2 | 10 |
2 | 2 | 0 | 3 | 2 | 3 | 8 |
3 | 5 | 3 | 0 | 3 | 1 | 5 |
4 | 1 | 2 | 3 | 0 | 1 | 3 |
5 | 6 | 4 | 1 | 1 | 0 | 2 |
6 | 10 | 8 | 5 | 3 | 2 | 0 |
Enter the node to display the routing table : 2
The shortest path from 2 to 1 = 2
The shortest path from 2 to 3 = 3
The shortest path from 2 to 4 = 2
The shortest path from 2 to 5 = 3
The shortest path from 2 to 6 = 8
Do u want to continue (y/n) : n
ROUTING TABLE FOR 2 :
| 1 | 2 | 3 | 4 | 5 | 6 |
1 | 0 | 2 | 3 | 1 | 2 | 4 |
2 | 2 | 0 | 3 | 2 | 3 | 5 |
3 | 3 | 3 | 0 | 2 | 1 | 3 |
4 | 1 | 2 | 2 | 0 | 1 | 3 |
5 | 2 | 3 | 1 | 1 | 0 | 2 |
6 | 4 | 5 | 3 | 3 | 2 | 0 |
Labels:
CSE - V SEM,
Network Lab Programs - CS2307
Subscribe to:
Posts (Atom)