ACN Mod-Multihost New
MULTI CLIENT
import java.io.*;
import java.net.*;
public class MultiClient
{
public static void main(String[] args) throws Exception
{
Socket socket = null;
PrintWriter out = null;
BufferedReader in = null;
try
{
socket = new Socket(“angel”, 4444); // ’angel’->own computer name
out = new PrintWriter(socket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
}
catch (Exception e)
{
System.out.println(“Error:”);
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String fromServer;
String toServer;
String fromUser;
System.out.print(“\nEnter data to Send: “);
while ((toServer = stdIn.readLine()) != null)
{
out.println(toServer);
fromServer = in.readLine();
System.out.println(“Server: ” + fromServer);
if (fromServer.equals(“EXIT”))
break;
System.out.print(“\nEnter data to Send: “);
}
out.close();
in.close();
stdIn.close();
socket.close();
}
}
=========================================
MULTI SERVER
import java.net.*;
import java.io.*;
public class MultiServer
{
public static void main(String[] args) throws Exception
{
ServerSocket serverSocket = null;
boolean listening = true;
try
{
serverSocket = new ServerSocket(4444);
}
catch (Exception e)
{
System.out.println(“Error:”);
System.exit(-1);
}
while(listening)
{
System.out.println(“Waiting for data….”);
new MultiServerThread(serverSocket.accept()).start();
}
serverSocket.close();
}
}
class MultiServerThread extends Thread
{
private Socket socket = null;
public MultiServerThread(Socket socket)
{
super(“MultiServerThread”);
this.socket = socket;
}
public void run()
{
try
{
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String inputLine, outputLine;
outputLine = “”;
while((inputLine = in.readLine()) != null)
{
synchronized(this)
{
outputLine = inputLine.toUpperCase();
out.println(outputLine);
System.out.println(“From Client: “+socket.getInetAddress().getHostName()+”->”+inputLine);
if (inputLine.equalsIgnoreCase(“exit”))
break;
}
}
out.close();
in.close();
socket.close();
}
catch (Exception e)
{
System.out.println(“Error:”);
}
}
}
ACN Mod-Pkt Analysis
import java.io.*;
import java.util.*;
class PAnalysis
{
static int nt=0;
static int nu=0;
static int pckt=0;
static int pcku=0;
static int szt=0;
static int szu=0;
public static void main(String args[]) throws Exception
{
FileReader fr=new FileReader(“input.txt”);
BufferedReader br=new BufferedReader(fr);
String s,s1;
while((s=br.readLine())!=null)
{
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)==’\t’)
{
check(s,i+1);
break;
}
}
}
System.out.println(“No of TCP Connection: “+nt);
System.out.println(“No of TCP packets: “+pckt);
System.out.println(“Total size of TCP packets received: “+szt);
System.out.println(“********************************************”);
System.out.println(“No of UDP Connection: “+nu);
System.out.println(“No of UDP packets: “+pcku);
System.out.println(“Total size of UDP packets received: “+szu);
fr.close();
}
public static void check(String s,int pos)
{
String s1=s.substring(pos,pos+3);
if(s1.equals(“TCP”))
{
nt++;
cal(s,true);
}
else
{
nu++;
cal(s,false);
}
}
public static void cal(String s,boolean flag)
{
StringTokenizer st=new StringTokenizer(s,”\t “);
String temp;
for(int k=0;k<7;k++)
temp=st.nextToken();
int no=Integer.parseInt(st.nextToken());
int size=Integer.parseInt(st.nextToken());
if(flag)
{
szt+=size;
pckt+=no;
}
else
{
szu+=size;
pcku+=no;
}
}
}
ACN Mod-Congestion control w/o timer
import java.io.*;
import java.lang.*;
import java.util.*;
class Control
{
public static void main(String args[])
{
int node,noc,i,sum=0,j,temp;
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the no of connections : “);
noc=sc.nextInt();
int con[]=new int[noc];
int pr[]=new int[noc];
boolean acc[]=new boolean[noc];
System.out.println(“Enter the size of the node : “);
node=sc.nextInt();
System.out.println(“Enter the size and type of each connection(1 for cbr,2 for vbr,3 for ubr,4 for abr) : “);
for(i=0;i<noc;i++)
{
con[i]=sc.nextInt();
pr[i]=sc.nextInt();
}
for(i=0;i<noc-1;i++)
{
for(j=0;j<noc-1-i;j++)
{
if(pr[j]>pr[j+1])
{
temp=pr[j];
pr[j]=pr[j+1];
pr[j+1]=temp;
temp=con[j];
con[j]=con[j+1];
con[j+1]=temp;
}
}
}
i=0;
while(node>0 && i<noc)
{
if ((node-con[i])>=0)
{
node=node-con[i];
acc[i]=true;
System.out.println(“Connection “+(i+1)+” accepted.”);
}
i++;
}
for (i=0;i<noc;i++)
if(!acc[i])
System.out.println(“Connection “+(i+1)+” rejected.”);
}
}
ACN-MultihostChat
CLIENT
import java.net.*;
import java.io.*;
public class SocketClient
{
public static void main(String[] args)
{
String host = “localhost”;
int port = 19999;
StringBuffer instr = new StringBuffer();
String TimeStamp;
System.out.println(“SocketClient initialized”);
try
{
InetAddress address = InetAddress.getByName(host);
Socket connection = new Socket(address, port);
BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream());
OutputStreamWriter osw = new OutputStreamWriter(bos, “US-ASCII”);
TimeStamp = new java.util.Date().toString();
String process = “Calling the Socket Server on “+ host + ” port ” + port +” at ” + TimeStamp + (char) 13;
osw.write(process);
osw.flush();
BufferedInputStream bis = new BufferedInputStream(connection.
getInputStream());
InputStreamReader isr = new InputStreamReader(bis, “US-ASCII”);
int c;
while ( (c = isr.read()) != 13)
instr.append( (char) c);
connection.close();
System.out.println(instr);
}
catch (IOException f)
{
System.out.println(“IOException: ” + f);
}
catch (Exception g)
{
System.out.println(“Exception: ” + g);
}
}
}
=============================================
Server
import java.net.*;
import java.io.*;
import java.util.*;
public class MultipleSocketServer implements Runnable
{
private Socket connection;
private String TimeStamp;
private int ID;
public static void main(String[] args)
{
int port = 19999;
int count = 0;
try
{
ServerSocket socket1 = new ServerSocket(port);
System.out.println(“MultipleSocketServer Initialized”);
while (true)
{
Socket connection = socket1.accept();
Runnable runnable = new MultipleSocketServer(connection, ++count);
Thread thread = new Thread(runnable);
thread.start();
}
}
catch (Exception e) {}
}
MultipleSocketServer(Socket s, int i)
{
this.connection = s;
this.ID = i;
}
public void run()
{
try
{
BufferedInputStream is = new BufferedInputStream(connection.getInputStream());
InputStreamReader isr = new InputStreamReader(is);
int character;
StringBuffer process = new StringBuffer();
while((character = isr.read()) != 13)
{
process.append((char)character);
}
System.out.println(process);
//need to wait 10 seconds to pretend that we’re processing something
try
{
Thread.sleep(10000);
}
catch (Exception e){}
TimeStamp = new java.util.Date().toString();
String returnCode = “MultipleSocketServer repsonded at “+ TimeStamp + (char) 13;
BufferedOutputStream os = new BufferedOutputStream(connection.getOutputStream());
OutputStreamWriter osw = new OutputStreamWriter(os, “US-ASCII”);
osw.write(returnCode);
osw.flush();
}
catch (Exception e)
{
System.out.println(e);
}
finally
{
try
{
connection.close();
}
catch (IOException e){}
}
}
}
ACN-Congestion control using admission control
import java.util.*;
class Main
{
static int pri[]={4,3,2,1};
static int bdw[]={5,4,3,2};
static int rem=10;
static int cp=0;
static int p[][]=new int [10][4];
public static void main(String ars[])
{
int i,j,k,m,ch,cprior,min,count=0,pos;
boolean done=false;
Scanner br=new Scanner(System.in);
System.out.println(“Enter choice \n 1 for CBR \n 2 for VBR \n 3 for UBR \n 4 for ABR”);
do
{
j=0;done=false;count++;
System.out.println(“Enter Details for “+count+” connection”);
System.out.println(“Enter Connection Type”);
m=br.nextInt();
cprior=pri[m-1];
if(rem>=bdw[m-1])
{
allocate(count,m);
done=true;
}
while(done!=true)
{
min=p[0][1];
pos=0;
for(i=0;i<cp;i++)
{
if(min>p[i][1])
{
min=p[i][1];
pos=i;
}
}
if(min>cprior)
{
break;
}
unallocate(pos);
if(rem>=bdw[m-1])
{
allocate(count,m);
done=true;
}
}
if(done==false)
{
System.out.println(“Connection Not Granted”);
}
System.out.println(“Enter 1 to continue”);
ch=br.nextInt();
}while(ch==1);
}
public static void allocate(int count,int m)
{
Scanner br=new Scanner(System.in);
System.out.println(“Enter time for connection”);
int t;
t=br.nextInt();
int j=0;
p[cp][j]=count;j++;
p[cp][j]=pri[m-1];j++;
p[cp][j]=bdw[m-1];j++;
p[cp][j]=t;cp++;
rem=rem-bdw[m-1];
System.out.println(“Connection Granted”);
}
public static void unallocate(int pos)
{
p[pos][1]=3000;
p[pos][3]=3000;
rem=rem+p[pos][2];
p[pos][2]=0;
System.out.println(“Connection “+p[pos][0]+” terminated”);
}
}
ACN-RIP Protocol
import java.util.*;
abstract class bell_ford
{
int MAX = 20;
int INFINITY = 9999;
int n;
int graph[][]=new int[MAX][MAX];
int start;
int distance[]=new int[MAX];
int predecessor[]=new int[MAX];
abstract void read_graph();
abstract void initialize();
abstract void update();
abstract void check();
abstract void algorithm();
}
class trial extends bell_ford
{
void read_graph()
{
Scanner kbd=new Scanner(System.in);
System.out.println(“Enter the no. of nodes in the graph ::”);
n=kbd.nextInt();
System.out.println(“Enter the adjacency matrix for the graph ::\n”);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
graph[i][j]=kbd.nextInt();
System.out.println(“Enter the start vertex ::”);
start=kbd.nextInt();
}
void initialize()
{
for(int i=1;i<=n;i++)
{
distance[i]=INFINITY;
predecessor[i]=0;
}
distance[start]=0;
}
void update()
{
for(int i=1;i<=n-1;i++)
{
for(int u=1;u<=n;u++)
{
for(int v=1;v<=n;v++)
{
if(graph[u][v]!=0)
{
if(distance[v]>distance[u]+graph[u][v])
{
distance[v]=distance[u]+graph[u][v];
predecessor[v]=u;
}
}
}
}
}
}
void check()
{
for(int u=1;u<=n;u++)
{
for(int v=1;v<=n;v++)
{
if(graph[u][v]!=0)
{
if(distance[v]>distance[u]+graph[u][v])
{
System.out.println(“does not exist’s “);
return;
}
}
}
}
System.out.println(“\n\nThere is no negative weight cycle and\n”);
System.out.println(“****** The final paths and the distacnes are ******\n\n”);
for(int i=1;i<=n;i++)
{
System.out.println(“path for node “+i+” is ::\n”);
int arr[] = new int[MAX];
int k=1;
int j=i;
while(predecessor[j]!=0)
{
arr[k]=predecessor[j];
k++;
j=predecessor[j];
}
for(k=k-1;k>0;k–)
System.out.println(arr[k]+”->”);
System.out.println(i);
System.out.println(“distance is “+distance[i]+”\n\n”);
}
}
void algorithm()
{
read_graph();
initialize();
update();
check();
}
public static void main(String args[])
{
trial obj=new trial();
obj.algorithm();
}
}
ACN Packet analysis
import java.io.*;
class Main
{
static int nt=0;
static int nu=0;
public static void main(String args[]) throws Exception
{
FileReader fr=new FileReader(“item1.txt”);
BufferedReader br=new BufferedReader(fr);
String s,s1;
char c;
int i,j,k,ct,cu;
while((s=br.readLine())!=null)
{
i=s.length();
for(j=0;j<i;j++)
{
c=s.charAt(j);
if(c==’,')
{
check(s,j+2);
break;
}
}
}
System.out.println(“No of TCP Connection: “+nt);
System.out.println(“No of UDP Connection: “+nu);
fr.close();
}
public static void check(String s,int j)
{
String s1=s.substring(j,j+3);
String t=”TCP”;
if(s1.equals(t))
{
nt++;
}
else
{
nu++;
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
import java.io.*;
import java.util.*;
class Main
{
static int nt=0;
static int nu=0;
static int pckt=0;
static int pcku=0;
static int szt=0;
static int szu=0;
public static void main(String args[]) throws Exception
{
FileReader fr=new FileReader(“item.txt”);
BufferedReader br=new BufferedReader(fr);
String s,s1;
char c;
int i,j,k,ct,cu;
while((s=br.readLine())!=null)
{
i=s.length();
for(j=0;j<i;j++)
{
c=s.charAt(j);
if(c==’,')
{
check(s,j+1);
break;
}
}
}
System.out.println(“No of TCP Connection: “+nt);
System.out.println(“No of TCP packets: “+pckt);
System.out.println(“Total size of TCP packets received: “+szt);
System.out.println(“********************************************”);
System.out.println(“No of UDP Connection: “+nu);
System.out.println(“No of UDP packets: “+pcku);
System.out.println(“Total size of UDP packets received: “+szu);
fr.close();
}
public static void check(String s,int j)
{
String s1=s.substring(j,j+3);
int m=1;
String t=”TCP”;
if(s1.equals(t))
{
nt++;
cal(s,m);
}
else
{
m=0;
cal(s,m);
nu++;
}
}
public static void cal(String s,int m)
{
StringTokenizer st=new StringTokenizer(s,”,”);
int size=9;
while(size>0)
{
size–;
String t=st.nextToken();
}
String t1=st.nextToken();
String t3=st.nextToken();
int n=Integer.parseInt(t1);
int si=Integer.parseInt(t3);
if(m==1)
{
szt+=si;
pckt+=n;
}
else
{
szu+=si;
pcku+=n;
}
}
}
/*
Output:
C:\Program Files\Java\jdk1.5.0\bin>cmd
Microsoft Windows [Version 6.0.6000]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Program Files\Java\jdk1.5.0\bin>javac Main.java
C:\Program Files\Java\jdk1.5.0\bin>java Main
No of TCP Connection: 49
No of TCP packets: 91523
Total size of TCP packets received: 19136683
********************************************
No of UDP Connection: 33
No of UDP packets: 33
Total size of UDP packets received: 7073
C:\Program Files\Java\jdk1.5.0\bin>
*/
ACN-Mail.java
import java.io.*;
import java.net.*;
public class mail {
public static void main(String[] args) {
try {
if (args.length >= 1) System.getProperties().put(“mail.host”, args[0]);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print(“From: “);
String from = in.readLine();
System.out.print(“To: “);
String to = in.readLine();
System.out.print(“Subject: “);
String subject = in.readLine();
URL u = new URL(“mailto:” + to);
URLConnection c = u.openConnection();
c.setDoInput(false);
c.setDoOutput(true);
System.out.println(“Connecting…”);
System.out.flush();
c.connect();
PrintWriter out =
new PrintWriter(new OutputStreamWriter(c.getOutputStream()));
out.println(“From: \”" + from + “\” <” +
System.getProperty(“user.name”) + “@” +
InetAddress.getLocalHost().getHostName() + “>”);
out.println(“To: ” + to);
out.println(“Subject: ” + subject);
out.println();
System.out.println(“Enter the message. ” +
“End with a ‘.’ on a line by itself.”);
String line;
for(;;) {
line = in.readLine();
if ((line == null) || line.equals(“.”)) break;
out.println(line);
}
out.close();
System.out.println(“Message sent.”);
System.out.flush();
}
catch (Exception e) {
System.err.println(e);
System.err.println(“Usage: java sndmail [your.mailserver.com]“);
}
}
}
AMP-switch cases-version2
To change upper case to lower and vice versa
; program for operations on strings
page 100,50
title string operations
mess macro msg ;definition of macro mess
mov ah, 09h
lea dx, msg
int 21h
endm
.model small
.stack 100h
.data
str1 db 25 , ? , 25 dup(‘$’)
str2 db 25 , ? , 25 dup(‘$’)
str3 db 25 , ? , 25 dup(‘$’)
msg1 db 0ah,0dh,’menu $’
msg21 db 0ah,0dh,’accept the string $’
msg6 db 0ah,0dh,’string is : $’
msg7 db 0ah,0dh,’ $’
.code ; data initialisation
mov ax,@data
mov ds,ax
mov es,ax
mess msg21
mov ah,0ah
lea dx,str1
int 21h
call convert
endd: mov ah,4ch
int 21h
;***************************************************************************
; convert cases
;***************************************************************************
convert proc near
lea si,str1+2 ; source string
lea di,str2+2 ; destination string
mov cl,str1+1
back: mov al,byte ptr[si]
cmp al,41h ; check if letter
jge bigg
jmp stop
smal : cmp al,61h ; check if letter is lower case
jge subb
bigg : cmp al,5ah ; check if letter is upper case
jge smal ; if greater letter is small case
add al,20h ; make letter lower case
branc:mov byte ptr[di],al ; move letter to destination
inc di
inc si
dec cl ; decrememt count
cmp cl, 00h
jne back ; check next character
jmp stop
subb: cmp al,7ah ; if small case letter
jge stop ; if not letter display as is
sub al,20h ; make letter upper case
jmp branc
stop: mess msg7 ; display result
mov ah,09h
lea dx,str2+2
int 21h
ret
convert endp
end
AMP-Devnagiri
AIM:-To convert english to devnagiri
.model small
; PROGRAM TO TYPE DEVANAGARI CHARACTER
.data
BUFF DB 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,1,1,1,1,1,1,1,1,1,1,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
DB 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
COL DW 0010H
ROW DW 0010H
SCOL DW 001FH
SROW DW 001FH
.code
START : MOV AX,@data ; Initialise data segment
MOV DS,AX
MOV AH,00H
MOV AL,06H ; Set graphics mode
INT 10H
MOV DX,ROW ; Initialise row and column
MOV CX,COL
XOR SI,SI
MOV AH,08H ; I/P from keyboard
INT 21H
CMP AL,’P’ ; If character is P, print
JNE STOP ; Otherwise terminate the
; program
DISP : MOV AH,0CH ; Write pixel
MOV AL,BUFF [SI]
MOV BH,00H
MOV CX,COL
MOV DX,ROW
INT 10H
INC SI
INC COL ; Increment column
MOV DI,SCOL
CMP COL,DI
JNE DISP
SUB COL,0FH
INC ROW ; Increment ROW
MOV BP,SROW
CMP ROW,BP
JNE DISP
MOV AH,08H ; I/P from keyboard
INT 21H
STOP: MOV AH,00H
MOV AL,03H ; Change mode
INT 10H
MOV AH,4CH ; Terminate
INT 21H
END START
Leave a Comment