Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1.a
1.b
1.c
E:\> msg * hi
2.a
import java.io.*;
import java.net.*;
class TestServer
try {
Socket s=ss.accept();
System.out.println("Accepted..");
InputStream in=s.getInputStream();
in.read(b,0,6);
System.out.println(new String(b));
catch(Exception e)
System.out.println(e);
}
}
----------------------------------
import java.io.*;
import java.net.*;
class TestClient
try {
OutputStream out=s.getOutputStream();
out.write("Hello".getBytes());
catch(Exception e) { System.out.println(e); }
}
2.b
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
InetAddress ia = InetAddress.getByName("192.169.0.231");
ds.send(dp);
ds.close();
}
import java.net.DatagramPacket;
import java.net.DatagramSocket;
ds.receive(dp);
System.out.println(strRecv);
ds.close();
}
3. Secured communication through encryption and decryption of messages.
import java.io.*;
import java.net.*;
class serverencrypt
{
try
Socket s = ss.accept();
System.out.println("Connected...");
String t ="Amazing";
int j;
int key = 3;
{ j=(int)t.charAt(i);
k=k+(char)(j+key);
out.write(k.getBytes());}
catch(Exception e)
System.out.println(e);
}}
4. Program for Remote procedure call under client server environment (RMI)
/* Program PrimeServer.java */
import java.net.*;
import java.rmi.*;
import java.io.*;
try {
Naming.rebind("PrimeServer", prime1ServerImpl);
catch(Exception e) {
/* Program PrimeClient.java */
import java.rmi.*;
import java.io.*;
int n;
try {
PrimeServerIntf prime1ServerIntf =
(PrimeServerIntf)Naming.lookup(PrimeServerURL);
System.out.println("Enter n");
n=Integer.parseInt(br.readLine());
catch(Exception e) {
/* Program PrimeServerIntf */
import java.rmi.*;
/* Program PrimeServerImpl.java */
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
implements PrimeServerIntf {
int count=0;
int i;
if(n==1)
System.exit(0);
for(i=2;i<n/2;i++)
if(n%i==0)
count++;
if(count>0)
}
else
return count;
6.
import java.nio.*;
class TcpServerCRC
{try{
Socket soc=ss.accept();
do
j = (byte)fin.read();
//s[m]=j.toString();
sb.append((char)j);
m++;}while(j!=-1);
String s1="";
divisor_bits=Integer.parseInt(br.readLine());
divisor=new int[divisor_bits];
divisor[i]=Integer.parseInt(br.readLine());
tot_length=s.length()+divisor_bits-1;//System.out.println("length "+tot_length);
div=new int[tot_length];
rem=new int[tot_length];
crc=new int[tot_length];
s="["+s+"]";
//System.out.println("data");
for(int i=0;i<s8.length;i++)
try
{data[i]=Integer.parseInt(s8[i]);}catch(Exception e){}}
/*for(int i=0;i<data.length;i++)
try
{System.out.print(data[i]);
}
catch(Exception e){}}
*/System.out.println();
for(int i=0;i<data.length;i++)
{System.out.print(div[i]); }
System.out.println();
rem[i] = div[i];
crc[i]=(div[i]^rem[i]);
}
System.out.println();
for(int i=0;i<crc.length;i++)
{ System.out.print(crc[i]);}
System.out.println();
//s.replaceAll("\\[","").replaceAll("\\]","").split("")
//Arrays.sort(crc);
//String[]
a=Arrays.toString(crc).replaceAll("\\[","").replaceAll("\\]","").replaceAll("\\,,","").replaceAll("\\,
","").split("");
// a=crc.replaceAll("\\[","").replaceAll("\\]","").replaceAll("\\,","").split("");
//s1=Arrays.toString(a);
String a=Arrays.toString(crc);
System.out.println(Arrays.toString(ar));
s1=Arrays.toString(ar);
String s9[]=s1.replaceAll("\\[","").replaceAll("\\]","").replaceAll("\\,","").split("");
for(int i=0;i<s9.length;i++)
{
System.out.print(s9[i].toString());
if(s1!=null)
for(int i=0;i<s9.length;i++)
byte jj[]=s9[i].getBytes();
fs.write(jj);
}}fs.close();
do
j=(byte)f.read();
soc.getOutputStream().write(j);
}while(j!=-1);
}}
catch(Exception e)
{}
}
static int[] divide(int div[],int divisor[], int rem[])
int cur=0;
while(true)
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);
cur++;
if((rem.length-cur)<divisor.length)
break;
return rem;
import java.io.*;
import java.net.*;
{try{
Socket socket = new Socket("127.0.0.1",2222);
byte b;
out.println(filename);
while((b=(byte)in.read())!=-1)
sb.append((char)b);
String s1=sb.toString();System.out.println(s1);
//String s8[]=s1.replaceAll("\\[","").replaceAll("\\]","").split("");
//s="["+s+"]";
//int j=0;
String az=s8[0].toString();
for(int i=0;i<s8.length;i++)
String s="";
/*if(s8[i].startsWith(","))
}*/
data[i]=Integer.parseInt(s8[i]);
//j++;
//i=i+2;
System.out.println("data");
for(int i=0;i<1;i++)
{
System.out.print(data[i]);
System.out.println();
System.out.print("string");
System.out.println();
for(int i=0;i<s8.length;i++)
System.out.print(s8[i].toString());
az="["+az+"]";
String sbuf[]=az.replaceAll("\\[","").replaceAll("\\]","").split("");
for(int i=0;i<sbuf.length;i++)
try
{datacrc[i]=Integer.parseInt(sbuf[i]);
}catch(Exception ex){}
System.out.println("datacrc");
for(int i=0;i<datacrc.length;i++)
try
{System.out.print(datacrc[i]);
catch(Exception ex){}
System.out.println();
{ divisor[i]=Integer.parseInt(br.readLine());}
rem[j] =datacrc[j];
}
rem=divide(datacrc, divisor, rem);
if(rem[i]!=0)
System.out.println("result : Error");
break;
if(i==rem.length-1)
}catch(Exception e){}}
int cur=0;
while(true)
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);
while(rem[cur]==0 && cur!=rem.length-1)
cur++;
if((rem.length-cur)<divisor.length)
break;
return rem;
/* program TestServer1ham.java */
import java.io.*;
import java.net.*;
import java.util.*;
int count=0; //........Initialising count to zero which will count the number of 1.
int l=a.length;
for(int i=0;i<l;++i)
if(a[i]==1)
if((count%2)==0)
else
ServerSocket ss;
Socket s;
try
System.out.println("waiting ");
ss=new ServerSocket(8085);
s=ss.accept();
System.out.println("connection established");
System.out.println("HAMMING CODE");
System.out.println();
int n=4;
int d[]=new int[4];
for(int i=n-1;i>=0;--i)
d[i]=scr.nextInt();
++k;
System.out.println();
System.out.println(k+" parity bits are required for the transmission of data bits.");
for(int i=0;i<=7;++i)
h[i]=-1;
int count=0;
int c=2;
while(count<4)
++c;
if(c==4)
continue;
h[c]=d[count];
++count;
int p1[]={h[1],h[3],h[5],h[7]};
int p2[]={h[2],h[3],h[6],h[7]};
int p3[]={h[4],h[5],h[6],h[7]};
parity[0]=set_parity_bit(p1);
parity[1]=set_parity_bit(p2);
parity[2]=set_parity_bit(p3);
h[1]=parity[0];
h[2]=parity[1];
h[4]=parity[2];
System.out.println("\nSENDER:");
System.out.print("\nThe data bits entered are: ");
for(int i=3;i>=0;--i)
System.out.print(d[i]+" ");
for(int i=2;i>=0;--i)
for(int i=(n+k);i>0;--i)
System.out.print(h[i]+" ");
while((x=(byte)h[i])!=-1)
t[i]=x;
i++;
out.write(t);
}catch(Exception e){System.out.println("Exception:"+e);}
/* TestClient1ham.java */
import java.io.*;
import java.net.*;
import java.util.*;
class Testclient1ham
int count=0; //........Initialising count to zero which will count the number of 1.
int l=a.length;
for(int i=0;i<l;++i)
if(a[i]==1)
if((count%2)==0)
else
try
InputStream in=s.getInputStream();in.read(b,0,10);
Scanner scr=new Scanner(System.in);
++k;
System.out.println();
for(int i=7;i>0;--i)
h[i]=scr.nextInt();
int p4[]={h[1],h[3],h[5],h[7]};
int p5[]={h[2],h[3],h[6],h[7]};
int p6[]={h[4],h[5],h[6],h[7]};
parity[0]=set_parity_bit(p4);
parity[1]=set_parity_bit(p5);
parity[2]=set_parity_bit(p6);
int
position=(int)(parity[2]*Math.pow(2,2)+parity[1]*Math.pow(2,1)+parity[0]*Math.pow(2,0));
System.out.println("\nRECEIVER:");
System.out.println("Error is detected at position "+position+" at the receiving end.");
if(h[position]==1)
h[position]=0;
else
h[position]=1;
for(int i=7;i>0;--i)
System.out.print(h[i]+" ");
catch(Exception e)
System.out.println(e);
}
7. RS232
“RS232EXAMPLE.JAVA”
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import gnu.io.SerialPortEventListener;
import gnu.io.PortInUseException;
import gnu.io.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
OutputStream out;
InputStream in;
int tail = 0;
super(Title);
setLayout(new FlowLayout());
add(tf);
add(sd);
add(ta);
sd.addActionListener(this);
addWindowListener(new wa(this));
send(mes.getBytes());
switch(event.getEventType())
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte b;
try
if (b=='\n')
onMessage();
else
buffer[tail] = b;
tail++;
}
onMessage();
try {
out.write(bytes);
out.flush();
catch (IOException e)
e.printStackTrace();
ta.appendText("connecting...\n");
try
{
SerialPort serialPort = (SerialPort) portIdentifier.open("RS232Example", 2000);
try
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
serialPort.setSerialPortParams(38400, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
out = serialPort.getOutputStream();
in = serialPort.getInputStream();
System.exit(0);
if (tail!=0) {
if ("BYE".equals(message)) {
send("ACK\n".getBytes());
this.dispose();
System.exit(0);
}
else if ("ACK".equals(message)) {
this.dispose();
System.exit(0);
tail = 0;
re.setVisible(true);
re.setSize(300, 300);
re.connect(args[0]);
RS232Example r;
this.r = r;
r.setVisible(false);
r.dispose();
System.exit(0);
}
PROTOCOL.JAVA
void onStreamClosed();
ListAvailablePorts.java
import gnu.io.CommPortIdentifier;
import java.util.Enumeration;
while(ports.hasMoreElements())
System.out.println(((CommPortIdentifier)ports.nextElement()).getName());
}
public static void main(String[] args) {
new ListAvailablePorts().list();
Commportreceiver.java
import java.io.IOException;
import java.io.InputStream;
InputStream in;
this.in = in;
try {
int b;
while(true) {
protocol.onReceive((byte) b);
}
protocol.onStreamClosed();
sleep(10);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
COMMPORTSENDER.JAVA
import java.io.IOException;
import java.io.OutputStream;
CommPortSender.out = out;
}
public static void send(byte[] bytes) {
try {
out.write(bytes);
out.flush();
} catch (IOException e) {
e.printStackTrace();
------
A) GO BACK N
//Go-Back-N
import java.io.*;
import java.net.*;
import java.util.*;
{
try
while(true)
System.out.println("socket created");
String st=br.readLine();
s.close();
s=new Socket("localhost",5555);
String error=scanner.nextLine();
out.writeBytes(error);
System.out.println("sent");
s.close();
Thread.sleep(100);
}catch(Exception e)
{}
import java.io.*;
import java.net.*;
try
int x=0,i;
String data=error;
error=" ";
int len=data.length();
for(i=0;i<burst;i++,x++)
data+=(char)('A'+x);
Socket s=ss.accept();
out.writeBytes(data);
System.out.println("sent");
s.close();
ss.close();
Thread.sleep(100);
ss=new ServerSocket(5555);
s=ss.accept();
System.out.println("waiting....");
error=br.readLine();
s.close();
ss.close();
}catch(Exception e)
{}
//Selective Repeat
//SERVER PGM
import java.io.*;
import java.net.*;
try
{
int i, error=0;
while(true)
int x=error;
int len=data.length();
for(i=0;i<len;i++,x++)
data+=(char)('A'+x);
Socket s=ss.accept();
out.writeBytes(data);
System.out.println("\n sent");
s.close();
ss.close();
Thread.sleep(100);
ss=new ServerSocket(5555);
s=ss.accept();
System.out.println("\nwaiting");
error=Integer.parseInt(br.readLine());
ss.close();
catch(Exception e)
{}
---
//Selective Repeat
//CLIENT PGM
import java.io.*;
import java.net.*;
import java.util.*;
try
while(true)
System.out.println("socket created");
String st=br.readLine();
s.close();
s=new Socket("localhost",5555);
String error=scanner.nextLine();
out.writeBytes(error);
System.out.println("sent");
s.close();
Thread.sleep(100);
}}
catch(Exception e)
{}
-------------
9. Distance vector
import java.io.*;
int i,j,k,n,src;
String ch;
n=Integer.parseInt(in.readLine());
for(i=1;i<=n;i++)
for(j=i;j<=n;j++)
if(i==j) a[i][j]=0;
else
{
System.out.println("\n Enter the distance between host : "+i+" and "+j);
a[i][j]=a[j][i]=Integer.parseInt(in.readLine());
System.out.print("\n");
for(i=1;i<=n;i++)
System.out.print("\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];
do
src=Integer.parseInt(in.readLine());
for(j=1;j<=n;j++)
if(src!=j)
{
if(a[src][j]!=100) System.out.println("\n The shortest path from "+src+" to "+j+" is
"+a[src][j]);
ch=in.readLine();
}while(ch.equals("yes"));
// dijkstra
class ShortestPath
{
// A utility function to find the vertex with minimum distance value,
// from the set of vertices not yet included in shortest path tree
static final int V=9;
int minDistance(int dist[], Boolean sptSet[])
{
// Initialize min value
int min = Integer.MAX_VALUE, min_index=-1;
return min_index;
}
// Driver method
public static void main (String[] args)
{
/* Let us create the example graph discussed above */
int graph[][] = new int[][]{{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, 0, 10, 0, 2, 0, 0},
{0, 0, 0, 14, 0, 2, 0, 1, 6},
{8, 11, 0, 0, 0, 0, 1, 0, 7},
{0, 0, 2, 0, 0, 0, 6, 7, 0}
};
ShortestPath t = new ShortestPath();
t.dijkstra(graph, 0);
}
}
Run on IDE
Output:
SYNOPSIS
sysctl is used to modify kernel parameters at runtime. The parameters available are those listed
under /proc/sys/. Procfs is required for sysctl(8) support in Linux. You can use sysctl(8) to both
read and write sysctl data.
PARAMETERS
variable
The name of a key to read from. An example is kernel.ostype. The '/' separator is also accepted in
place of a '.'.
variable=value
To set a key, use the form variable=value, where variable is the key and value is the value to set
it to. If the value contains quotes or characters which are parsed by the shell, you may need to
enclose the value in double quotes. This requires the -w parameter to use.
-n
Use this option to disable printing of the key name when printing values.
-e
-w
-p
Load in sysctl settings from the file specified or /etc/sysctl.conf if none given.
-a
-A
/sbin/sysctl -a
/sbin/sysctl -n kernel.hostname
/sbin/sysctl -w kernel.domainname="example.com"
/sbin/sysctl -p /etc/sysctl.conf
sudo sysctl -p
/sysctl.conf by default.
TCP keepalive
Transmission Control Protocol (TCP) keepalives are an optional feature, and if included must
default to off. The keepalive packet contains null data. In an Ethernet network, a keepalive
frame length is 60 bytes, while the server response to this, also a null data frame, is 54 bytes.[3]
There are three parameters related to keepalive:
Keepalive time is the duration between two keepalive transmissions in idle condition. TCP
keepalive period is required to be configurable and by default is set to no less than 2 hours.
Keepalive interval is the duration between two successive keepalive retransmissions, if
acknowledgement to the previous keepalive transmission is not received.
Keepalive retry is the number of retransmissions to be carried out before declaring that remote
end is not available.
------------------------------------------------------------------
and grep this list for net.ipv4 settings (sysctl -A | grep net.ipv4).
You can manipulate with these settings using the following command:
This sample command changes TCP keepalive timeout to 60 seconds with 3 probes,
10 seconds gap between each. With this, your application will detect dead TCP connections after
90 seconds (60 + 10 + 10 + 10).
proc finish {} {
global ns nf1
$ns flush-trace
close $nf1
exit 0
$ns run
#
# Redistribution and use in source and binary forms, with or without
# are met:
# 4. Neither the name of the University nor of the Laboratory may be used
# SUCH DAMAGE.
# Simple demo script for the new APIs to support multi-interface for
# wireless node.
# Define options
# Please note:
# -channelType $val(chan)
# ...
# But we recommend you to use node-config in the way shown in this script
# Create God
create-god $val(nn)
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF \
-channel $chan_1_
# node_(1) can also be created with the same configuration, or with a different
# channel specified.
# Uncomment below two lines will create node_(1) with a different channel.
# $ns_ node-config \
# -channel $chan_2_
$node_(0) random-motion 0
$node_(1) random-motion 0
proc stop {} {
$ns_ flush-trace
close $tracefd
}
puts "Starting Simulation..."
$ns_ run
12 a:
#Schedule events for the CBR agent and the network dynamics
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n(1) $n(2)
$ns rtmodel-at 2.0 up $n(1) $n(2)
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
12 b:
proc finish {} {
global ns f0 f1 f2 f3
$ns flush-trace
close $f0
close $f1
close $f2
close $f3
exit 0
return $traffic
}
proc record {} {
To study and understand the architecture and topology adopted in SASTRA infrastructure.
DESCRIPTION:
Central computing facility controls the IT infrastructure of over 2500 computer with latest
software and operating system.
It provides 24 hours access to 370MBPS internet level that is network though the computer
Novell window and unix servers super computer linux cluster and blade servers with
quadcore.Intel dell xenon processor,2.66GHz 8GB PCZ-3500.FDB DDR 2Ram 3AS 10K 3FFR
HDD with Raid providers a powerfil server architecture at SASTRA.
It user the router which provider comprehensive scalable and serve network routing which is
connected to bsnl and reliance 20Mbps.
The forti gate firewall connected two modem,forti analyzer,DITZ,Mz.The forti gate firewall has
Z features.
SASTRA has three layered switch which is connected to the buildings.This zone is called
militarized zone.
The forti range from 1-126 class A,class B from 128-191, class C from 192-223, class D from
224-239 , class E from 240-254. Private IP for each class
ADDITIONAL EXPERIMENTS
QUEUE MONITORING
# s1 s3
# \ /
# r1 --------- r2
# 10Mb,3ms / \ 10Mb,5ms
# / \
# s2 s4
#
# Tracing a queue
$ns at 10 "finish"
proc finish {} {
global tchan_
set awkCode {
set end $2
close $tchan_
puts $f \"queue
puts $f \n\"ave_queue
close $f
$ns run
MULTICASTING
$ns multicast
$ns trace-all $f
# prune/graft packets
proc finish {} {
global ns
$ns flush-trace
exit 0
$ns run
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
$ns run