You are on page 1of 17

Program For OSI Model

# include<graphics.h> # include<stdio.h> # include<stdlib.h> #include<conio.h> Void main() { Intgdriver=DETECT, gmode,errorcode; Intleft,top,right,bottom; Intgraph(&gdriver,&gmode,c:\\tc\\bgc); rectangle(5,10,100,34); rectangle(500,10,600,34); rectangle(5,45,109,64); rectangle(5,79,100,198); rectangle(5,109,100,128); rectangle(5,142,100,160); rectangle(5,205,100,224); rectangle(500,45,609,64); rectangle(500,45,609,64); rectangle(500,79,600,96); rectangle(500,109,600,128); rectangle(500,142,600,160); rectangle(500 ,175,600,192); rectangle(1500,175,600,192); rectangle(500,205,600,224); rectangle(500,10,600,34); line(100,124,500,24); line(100,54,500,54); line(100,86,500,118); line(100,118,500,118); line(100,150,500,150); line(100,214,500,214); line(100,214,180,182); gotoxy(2,2);
1|P ag e

printf(application); gotoxy(2,2); printf(application); gotoxy(65,2); printf(application); gotoxy(2,4); printf(presentation); gotoxy(65,4); printf(presentation); gotoxy(2,6); printf(session); gotoxy(65,6); printf(session); gotoxy(2,8); printf(transport); gotoxy(65,8); printf(transport); gotoxy(65,8); printf(transport); gotoxy(2,10); printf(network); gotoxy(20,10); printf(network); gotoxy(45,10); printf(network); gotoxy(85,10); printf(network); gotoxy(2,12); printf(data link); gotoxy(20,12); printf(data link); gotoxy(65,12); printf(data link); gotoxy(35,3);
2|P ag e

printf(peer to peer); gotoxy(2,14); printf(physical); gotoxy(45,14); printf(physical); gotoxy(65,14); printf(physical); gotoxy(35,5); printf(peer to peer); gotoxy(35,7); printf(peer to peer); getch(); closegraph(); }

3|P ag e

Program For Client Server Using Java


import java.io.*; importjavax.swing.*; import java.net.*; importjava.awt.*; importjava.awt.event.*; public class ChatRoom12MClient extends Panel { TextArearecievedText; Socket sock; Private Grid Bag Congtraints c; Private Grid Bag Layout grid Bag; Private Frame frame; Private Label label; JButton send; JButton exit; Private int port=5001; Private TextAreasendText; Private String hostName; Private String userName Private DataOutputStreamremotrOut; ImageIcon i1.i2; public static void main(String args[]) { if(args.length!=2) { System.out.println(Format is : java ChatRoom12M client); return ; } Frame j1=new Frame(Welcome Protocol); j1.resize(800,600); j1.show(); JOptionPane.showMessageDialog(j1,welcome+args[0]+----+have ,welcome,U);
4|P ag e

nice

session

Frame j=newFrame(connection to Mr. XYZ+args[0]); ChatRoom12M client chat=new ChatRoom12MClient (j,args[0],args[1]); j.add(centre, chat); j.setSize(800,600); j.show(); chat.client(); } public ChatRoom12MClient(Frame,F,String, user,String sort ) { frame =j; frame.addWindowListener(new WindowEventHandler()); UserName=User; HostName=Host; c.inserts=inserts; c.grids=j; Lavel=new Lavel(Text to send); add(lavel); c.gridx=j; add(send text); Lavel=new Lavel(Text reciever); add(Lavel); receiver Text=new TextArea(15,30); add(receiver Text); ImageIcon i1=new ImageIcon(click.gif); ImageIcon i2=new ImageIcon(doorin.2.gif); send=new JButton(i1); ocit=new JButton(i2); add(send); add(exit); send.addActionListener(new TextActionHandler()); exit.addActionListener(new exit()); } void client() {
5|P ag e

try { if(hostname.equals(local)) hostname=null; InetAddress server Addr=InetAddress.getByName(hostName); sock=new Socket(server Addr.getHostName().port); remoteOut=new Data OutputStream(sock.getOutputStream()); System.out.println(Converted +sock.getPort()); } catch(IOException e) { System.out.println(e.set message() + : Failed to connect to server); } } Protected void finalize() throws throable { System.out.println(x.set message() + : connection to peer host ); } } } } class ChatRoom12MClient Receive(ChatRoom12MClient Chat) { this.chat=chat; } public Synchronized void run() { String s; DataInputStreamremotein=null try { remotein = new DataInputStream(chat.sock.getInputStream()); while(true)
6|P ag e

to

server + ServerAddr.getHostName()

On Port

new ChatRoom12MClient Reciever(this).start();

{ s=remoteIn.readUTF(); Char.recievedText.setText(s); } } catch(IOException e) { System.out.println(e.get message() + :Connection to peer host); } Finally { try { if(remoteIn!=null) remoteIn.class(); } catch(IOException x) } } }

7|P ag e

Program for character transmission by simplest method


# include<iostream.h> # include<conio.h> # include<dos.h> # define COM 1 0 # define settings (0*801|0*802|0*001|0*00) Void main() { clrscr(); char a; bioscom (0, SETTING, COM1); Cout<<enter the character to transfer; a=getch(); bioscom(1,a,com1); getch() } RECEIVER # include<iostream.h> # include<conio.h> # include<dos.h> # include<bios.h> # define COM 1 0 # define settings (0*801|0*802|0*001|0*00) Void main() { clrscr(); classwindowexithandler extends Window Adapter { public void Window Closing (WindowEvent e) { Window w=e.getWindow(); w.getVisible(false); system.exit(0);;
8|P ag e

} } class EXIT implements ActionListener { public void actionPerformed(ActionEvent e) { if(JoptionPane.showConfirmDialog(nw session))==JoptionPane.Yes_OPTION) { JOptionPane.showMessageDialog (new frame(), Thanks, Visit Again ,Good Bye,0); System.exit(0); } } } classTextActionHandler implements ActionListener { public void actionPerformed(ActionEvent e) { try { remoteOut.WriteUTE(Send Text.getText()); sendText.setText( ); } catch(IOException x) } } Private void broadcast (Strings s) { Vector client = Server.getClient(); Data Outputstreamdataout = null for(Enumeration e = clients.elements()); e.hasMoreElements(); { char a; bios com(0, Setting, COM1); Cout<<enter the character to transfer;
9|P ag e

Frame

+Are

you

sure

to

class

a=getch(); bioscom(1,a,COM1); getch(); } RECEIVER # include<iostream.h> # include<conio.h> # include<dos.h> # include<bios.h> # define COM 1 0 # define settings (0*801|0*802|0*001|0*00) Void main() { clrscr(); char a; bioscom(0, setting, com1); b=b*0*00011; a=b; Sleep(3); cout<<a; } } try { if remote out != Null remoteout.close(); if(sock!=Null) Sock.close(); } Catch(IO Exception) { Superfinalize(); } data.out = (DataOutputStream)(e.nextStatement());
10 | P a g e

if(!dataOut.equals(remote out)) { try { data.out.write.if(l); } { Catch(IO Exception.x) { S.O.L.(x.getmessage()+Sailed); Server.Remote from clients(dataOut); } } } } public void clear up() throws IO Exception { if remote out != Null; } if(remote(n!=null) { remoteln=Null; } if(Sock!=null) { Sock.Close(); Sock=Null; } } Protected void Finalize() throws throwable { try { cleanup();
11 | P a g e

} } if(Server sock !=null) { try { serversock.close(); } catch(IOExcetion x) } } } } SERVER SIDE import java.io.*; import java.net.*; importjava.util.Enumeration Public class chatRoom 12m Server { Private int Port = 1003; Private int Port = 1001; Private boolean l = null; } Private vector reciver = new vector(); public static void main (String args[ ]) { SOL(press CTRL to quit); newchatroom {2m Server(), Server} } Void Server( ) { Enum Socket Server sock = Null; Try {
12 | P a g e

SOL(Waiting for+Serveraddr.gethost Name( )+ On PST+post) Server Sock = new Server Socket(Port,50); } Catch(IOException) { system.out.println(i.getmessage( )+ failed) return; } While(i) { try { Socket socket= Server sock.accept( ); SOL (accept+Socket.getnetaddress().get last name) DataOutputStream remote out = new DataOutputStream (Socket.getOutputStream( )); client add element(remote out); newServerHelper(socket remoteout , char); Catch(IOException e) { System.out.println(e.getmessage()+ Sailed); Catch(IOException e) Super finalize( ); } }

13 | P a g e

Program For Implementing Token Bucket Algorithm


#include<stdio.h> #include<conio.h> #include<math.h> #include<string.h> #include<iostream.h> #include<bio.h> #define COML1 #define SETTINGS(0x80|0x02|0x00|0x00) void main() { int un; charstr[5]; clrscr(); lrioscam(0,SETTINGS,COM2); while(1) { cout<<enter string to transfer; gets(str); un=strln(str); for(int i=0;i<len;i++) { cout<<str[i] newscam(1,sh[i],com2);}} getch(); } #include<stdio.h> #include<conio.h> #include<math.h> #include<string.h> #include<iostream.h> #include<dos.h> #deine COM 4
14 | P a g e

#define SETTINGS(0x8010x02|0x00|8x00) void main() { chara,s[5]; intI,z=0,x; close_lrstart,end; clrscr(); lrioscam(0,SETTINGS,COM 2); start=close(); k=0; while(s[k-1]=\0) { char=lrioscam(2,0,win 2); char n=1 &0x0011; if(n==\0) {s[x]=n; x++; if un2=A && n<=2) || (n>=0 && n<=z) || (n>=0 && n<=g)) { s[k]=n; k++; end=close(); z=next[(end=start)]|k-[lk]|)+z; i=0; while(i<z && s[i]!=\0){ cout<<s[i]; i++; } if(k<z){ cout<<(\n start<<(z-k)<<token remains); z=z-k; } else z=0; for(i=0;i<=k;i++) { s[i]=0; } goto(1); getch();}
15 | P a g e

Program For Path Between Nodes


#include<stdio.h> #include<conio.h> #include<process.h> #include<strlib.h> #define permanens 1 #define textalive() #define infinity 10000 intu,j,n,k,min,list[10][10],path[10]; struct state { int predecessor; intlenth; int label; struct state*p; voidget_air() { cout<<enter how many nodes) list>n; for(i=0;i<n;i++) { list[i][i]=0; for(i=0;i<n;i++) { for(j=j+1;j<n;j++) { cout<<enter distance between nodes<i++&<<j++<<:; cin>>list[i][j];}}} voidshortest_path(ints,int h); { for(p=&state[0]); p<&state[n];p++) { p->predecessor=-1;
16 | P a g e

p->length=infinity; p->value=null; state[t].length=0; state[t].label=permanens; k=t; do{ for(i=0;i<n;i++) { if list[k][i]!=0 && state[i].label=tentative) { if (state[k].lenght+list[k][i]<state[i].lenght) { state[i].predecessor=k; state[i].length= state[k].length +list[k][i];}}} state[]k.label=1; }while(k!=s); i=0; k=s; do{ push[i]=k; cout<<path[i]+1<< ; k= state[k].predecessor;} }while(k>0);{ void main() { intsource,destt; clrscr(); get_dir(); cout<<\n enter source number:); cin>>source; cout<<enter destination number); cin>>dest; shortest_path(source-1,dest-1); getch(); }
17 | P a g e

You might also like