You are on page 1of 22
a Page No. oF Cy LOYOLA-ICAM COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) Exp.no: 2 Date: 240% 022 Write a HTTP web client program to download a web page using TCP sockets. Aim: To download the webpage. using Tosa. Algorithm: Chent: D Start the program DC oa socket whith birds ‘the TPaddwss of server and th portaddass to Acquire sewict. D Atha establiehing conmuction sunk the v7! do suver. D open a fle and store the ruled data trio “the file. 5) Tounlead the contint url ntafvid and send 2) Crete a server socket to activate the post Addiss, 2) Cnote a socket for the 8uve7 whith acuple the 311120205017 BHUVANESH RAAM CK CVs IUUULDUVUHUUULULOEECEE CCCeCeeYM % } LOYOLA-ICAM Pagena| 1014 @ COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) comicton. 4+ After eobabifelfing conrucfion recive vit frome te (ent 5+ Douwntood. He comkmt of OIL aeuitvect anol aro! “the dota +o te Clint. b- Close the serket, Te End the program. Program: import java io BufferedReader impor java io.Buflered Writer, import java.io.FileWriter; import java.io. InputStreamReader, import java.net URL: public class Main { public static void main(Strirtgf{ args) throws Exception { URL url= new URL("htps://www google.com"); BufferedReader reader = new BufferedReader{new InputStreamReader(url.openStream())), BufferedWriter writer ~ new BufferedWriter(new FileWriter(“data,himt")); String line; while ((line = reader readLine()) != null) { System.out printin(line); writer write(line); writer. newLine(): } reader close(); writer close); BHUVANESH RAAM CK Page No. to cy LOYOLA-ICAM COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) Exp.no: 3a Date: 2409-22 TCP Sockets - Echo Aim: To witte a Jove. program for opplication using TCP socket links, Algorithm: Cl*ents 1) Start 2) Create the TC? Socket. D Establish conntion wPth the sawy. 4) Get the massag 10 from “the use7. D Send the missay tothe stave. 2) Pecstve the D Dreplay seam, echoed by the server. miseagp, TWaeNed from the save. % Terntinate the connuctfon, ® Stop. Servers D Start D Creocte TOP se ket. and. make Pha Fistcting socket. 311120205017 BHUVANESH RAAM CK Page No. i LOYOLA-ICAM _ COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) 2) Acepk the connection requiot sunt by the Cirerite 4 Vieplay the wustud rresog., © Bend the ritived mesag to the client he which Tt -vecehse 6) Close the connection whin clfent rffictes tarination and Seivea— becores wating fox Clients . 7) Stop, Program: Client: a "obning server import java.io.*; import javanet.*; public class eclient { public static void main(String args[]) { Socket ¢ = null; ‘String line; DatalnputStream is, is]; PrintStream os; wy { c= new Socket("localhost”, 8080); } catch (IOException e) { ‘System.out printin(e); } ty { 311120205017 BHUVANESH RAAM CK gr, Page 6 ¢ ) LOYOLA-ICAM ie ' & COLLEGE OF I NGINLERING AND TLCHNOI OGY (LICE T) Faxp.no: 3b Date: 7A, 2.2 Chat Application ‘Alm: 10 Tptenint a Chat application voing TCP eke. Algorithm: Ci?fents 'o Start the Progaarn. Ze Tiiclude th, numsoary package ea Java. 3 To cHate a Socket in cient to server. 4° The Citert stables a connction to the DUTVEA, Ge The Cifent atapt dota from Chtent connettfon and + snd saver, 6. The Citerst 4 the russage Te Gop the Popa. Devers 40 Stoit Ze Trelude heussary packogt ‘in fava. BHUVANESH RAAM CK ieerhe the ater to send “the end 311120205017 gweuouevuvveeveeeeee © © & HF &G eH oS © »x~UvVIU “evvw Fuvsw Page No LOYOLA-ICAM y ae COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) %- To cuate o sacket Fn surver te cPerth 4o The server tstallishes a connection +p -the Cllert. Be “The Seavey Auepts the connection and 10 und The date from sewer to cient and Vite-wrsa. 6+ The sewer Communicaks the client to senol the ond op the rrussa% . Te Stop the program. Program: Client: import java.net.*; import javaio.*; public class TCPclient { public static void main(String args{]) throws Exception { Socket os = new Socket("localhost”, 1234); BufferedReader kb = new BufferedReader(new InputStreamReader(System.in)); BufferedReader br = new BufferedReader(new InputStreamReader(cs.getInputStream())); DataOutputStream dos = new DataOutputStream(cs.getOutputStream()); System.out printin("Enter Text: "); System.out printin("If client ‘qui’ type 311120205017 BHUVANESH RAAM CK Page No 20 LOYOLA-ICAM COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) Exp.no: 3¢ Date: 76402 2 File Transfer Aim: TO UP. a Fava program for fe brarsfer using TCP sockets. Algorithm: Clrents 1 Tmport fava. packages ano crake class file server. 2° Create a ru Seavey socket and binol Pt. to “the porte %. Nour connection 76 eedablt 4° The object Ci a nol Radix clase 7s usec fos siefing dota cofint utith has ben rech¥eved from the, socket Abfect. §. The connection f5 closed« 6. Sip the Progam. bervers 'o Lrnport fava prekages and creat clase file Sewer. 311120205017 BHUVANESH RAAM CK fee LOYOLA-ICAM =—- "eNO 2 & g COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) 20 Cue @ mur suiviy sockit ond Bind # © the porte be Acept the Chur conection. Ae Get the fluname and store th ro the Buyer Reader. 5 ¢ wok a nur ofect clase file 6 reaol ne 6. Th the fle ofsts un file recy reals the conbnt unl EOF 75 aeachde Te Stop the Progra. Program: Client: import java.io BufferedOurputStream; import java.io FileOutputStream; import java.io InputStream; import java.net. InetAddress; import java.net. Socket; public class FileClient { public static void main(Stringf] args) throws Exception { Socket socket = new Socket{InetAddress.getByName("localhost”), 5000); byte{] contents = new byte[ 10000]; FileOurputStream fos = new 311120205017 BHUVANESH RAAM CK YY LoyoLaicam = "8 / COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) Exp.no: 4a Date: 140% 22 Address Resolutio Protocol Aim: To wrt. a Jova, program for the sirnulation of Addvss Resolution Protocol using TCP. Algorithm: Cifernts 1. Stayt -the program. 20 Croce = secket and establibh conructPon wrth the aciver B. Get the IP addwsg to be converted. Frto MAC addase from the wea? 42 Sencl thts IP dass tO server. B RecWe the MAC addatss 4" the IP adduss from the sever. Ge Display the veecfvel, MAC adolress. Te Teimnate te connectfon. Beets 'e Start the program. 311120205017 BHUVANESH RAAM CK LOYOLA-IcCAM = “ee % COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) 20 Create the secket. biol the socket craked with TP addatss ano, port numer and make fra Neterfing sockate de Aceph the connicfon nqust whin Pb fo requss teal by he client a 4e Se1ve1 molfitttins tht tale Fn eolith IP corresponding MAC adaa. are ston. Be Receive the LT? addwss set by the. cRurtte 6. Rebeve the corneporiting addasse 497 the TP addatss and sino t+ +o Ane cRinte Te Close the connection. Go Stop. Program: Client: import java.io.*; import java.net.*; import java.util.*; public class Client ARP { public static void main(String args(]) { uy { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); Socket clsct = new Socket("127.0.0.1", 5604); DatalnputStream din = new DatalnputStream(clsct.getInputStream()); DataOutputStream dout = new 311120205017 BHUVANESH RAAM CK . Page N 24 f LOYOLA-ICAM ¢ COLLEGE OF ENGINEERING AND TECHNOLOGY (LI Exp.no: 4b Date: /40%42 2 Reverse Address Resolution Protocol Aim: + (e7) Yo ute a program ¢ TONITSE prekool using user dackagrarn probeol- Algorithm: addriss reeolsfion Clents to Start the program. 2° Cote dortnarrar. socket. Be Get the MAC addass +o be canirizl Frio I? addiss fem the usr 4° Seno -+tHig MAC addres 40 s2V01 usta UDP d datagram. Be Reaive the dactag va from the saver and d&play the 1765 porting TP/addsiss. 6. Stop. Srvrs to Start the program. 20 Server mndfintains the table tn whth the 311120205017 BHUVANESH RAAM CK ¢ y / LoYoLAicam 8 ; COLLEGE OF ENGINEERING AND TECHNOLOGY (L conntepond.ing MAC addyese ate stond- Be Chote detmaram socket. ° Ae Recee the clatagram socket by the cfrurt and rok the MAC addriss sutte Be Ret? tileve the IP addriss and wivel addres from the tabi. 6. De foplay the Corresponding P address. Te Stop. Program: Client: ‘import java. import java.net.*; import java.util.*; class ClientRARP { public static void main(String args{]) { uy DatagramSocket client ~ new DatagramSocket(); InetAddress addr = InctAddress.getByName("127.0.0.1");, bytef] sendbyte ~ new byte| 1024]; bytef] receivebyte ~ new bytel 1024]; 311120205017 BHUVANESH RAAM CK Page No. a ey LOYOLA-ICAM 4 COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) Exp.no: § Date: 124022 Simulation of DNS using UDP sockets Aim: 10 wrtte a Jove pragrarn fo the simulation % NS ushng UDP ett. Algorithm: Severs le Start. 2o Crate Upp aectagrarn socket. ® Crate a table theck maps est naire and +P address, 4o Reuive the name for the cent. Be Retiiwe the Clute LP adduss fiom the Wed datagram, 6 Gut the TP address mapped for the hest hame from the table. 7 Display the host name and corsespordng TP addins, B+ Send dhe TP ayolrisg ra she req ussited bog nore +0 -the clPutt. eo Stop. 1. Stork Cunt : 2: Grote UDP derke gram sotkit - 311120205017 4, Gy host ard fora BHUVANESH RAAM CK the client evvvv BP SDD a Page No a LOYOLA-ICAM seme (OE ae COLLEGE OF ENGINEERING AND. TECHNOLOGY (LICET) Be Wott fr the ply fren cthe sewer. Recive the upy ‘eqen and wad the TP addr. 6. Dieplay the tp address. 0 Step. Program: Client: ‘import java.io.*; import java.net.*; public class udpdnsclient { Public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System in)) DatagramSocket clientsocket = new DatagramSocket(); InetAddress ipaddress; if (args.length == 0) ipaddress = TnetAddress.getLocalHost(); else ipaddress = InetAddress.getByName(args(0]); byte[] senddata = new byte[1024]; byte{] receivedata = new byte{1024]; int portaddr = 1362; System.out.print("Enter the hostname : "); String sentence = br.readLine(); senddata = sentence. getB DatagramPacket pac} new DatagramPacket(senddata, senddata.length, ipaddress. ‘acket recvpack = new DatagramPacket(receivedata, receivedata length); clientsocket.receive(recvpack); String modified = new String(recvpack.getData()); System.out.printIn("IP Address: " + modified); clientsocket.close(); import java.io.*; import java.net.*; sserver { indexOf{Stringl] array, String str) { str.trim(); for (int i = 0; i < array.Jength; i++) { if (array[i].equals(str)) 311120205017 BHUVANESH RAAM CK Loyota-icam = "N° 4 COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) e LOYOLA-ICAM COLLEGE OF ENGINEERING AND TECHNOLOGY (L do ‘tep ogunt 8+ Conve ep and “lp sink. Ao 5 , Run the 6 iruslation Program: TCP Performance set ns (new Simulator] Sns color 0 Blue Sns color 1 Red Sns color 2 Yellow set nO [Sns node] set nl [Sns node] set n2 [Sns node] set n3 [Sns node] set f [open tepout.tr w] Sns trace-all Sf set nf [open tepout.nam w] Sns namtrace-all Snf Sns duplex-link $n0 $n2 SMb 2ms DropTail Sns duplex-linkwpSn2 $n3 orient right Sns duplex-link-op $n2 $n3 queuePos 0.5 set tep [new AgenUTCP] Step set class_ 1 set sink [new Agen/TCPSink] Sns attach-agent $n! Step $ns attach-agent $n3 $sink $ns connect Step Ssink set fip [new Application/FTP] Sfip attach-agent Stcp $ns at 1.2 "$ftp start" Page No $ns at 1.35 "Sns detach-agent $n! Stcp ; $ns detach-agent $n3 Ssink" 311120205017 BHUVANESH RAAM CK Page No 44 LOYOLA-ICAM COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) EXp.no: 8 Date: 239,22 Simulation of Distance Vector/ Link State Routing Algorithm Alm: To smulate the adARstanee veer and blink state Toating protocol usthg N52, Algorithm: Lwk Stode Poucing: '" Creo a Strulortor objecto 2° Set vouting 0 clynammc, 3. Opin the 4traw and Nam row fs. 40 Defire the ato proadane. 5» (Hate nodes and Ioks betwen them 8 Corte Hue agurte and attach thim +p the hole, " Cweate the applfeatfons anc attoeh tum to udp agents %. Connect udp andiall, a6 At isec tak foe At 2 sec biePun rede 1 anc 2 %5 brokin, Yak 15 up ogatn Simulaton. Diotanee Vectors 'o Cttote © skauletos obfeck 20 Set Touting pretecel to Distane vector wuthg Bo Trae packits on all Inky orte NAM tau and tart trace fre. 4+ Define Finfoh pretelure to close US. LLsh 311120205017 BHUVANESH RAAM C K . LOYOLAIcAM = **"N0 og & COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) ageing and tun NAN, Se Add a stale agunt 40 noole hg 60 Gnnect sour and. Hu sh 7 Schudule the everts anol start the Schedules. 8+ Observe the “hagpe reute when [ink % up anol down. VPur the simulated events and trace file analyse #4, ag, End. Program: Distant Routing Vector: set ns [new Simulator] set nf [open out.nam w] Sns namtrace-all Saf set tr [open out.tr w] $ns trace-all $tr proc finish {} { global nf ns tr $ns flush-trace close Str set n2 [Sns node] set n3 [$ns node] Sns duplex-link $n0 $n1 10Mb 10ms DropTail Sns duplex-link $n1 $n3 10Mb 10ms DropTail Sns duplex-link $n2 $n1 10Mb 10ms DropTail Sns duplex-link-op $n0 $n! orient right-down Sns duplex-link-op Sn! $n3 orient right Sns duplex-link-op $n2 Sn! orient right-up set tcp [new Agent/TCP] Sns attach-agent $n0 Step set ftp [new Application/FTP] Sfip attach-agent Step 311120205017 BHUVANESH RAAM CK Page No 4 LOYOLA-ICAM 7 4 COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) Date: 5, 10022 Performance evaluation of Routing protocols using Simulation tool Aim: To wit, a nso program for iaplrmanting urFeast routing protecolcnck mulifeast routing pactoce/ Algorithm: 'e Start the pregqtam 2e Declare the global varFables ng for cmattng * neu ¢?mulotor. ‘ Be Set the color ~ packets. 4e Open the network an?motoy File in the name fie 2 Pa the ussite mods. 5e Optn the trae fie Gn the mame of Fu Th the wire mool. 6. Sut the urfteast © ) pretocel do transhiy the packets Tn nekwork, ‘qutrel ne. hedis, $+ Gethe posttfon fer the fnks betwan tire nods. 1. Stta tep TNO connerHon for Seure neols. 10. Set the cistfration node Using tep sink. re Sttaye 2 ftp connection over the ep comy ctor ‘2+ Difira the fave. Procedure. 311120205017 BHUVANESH RAAM CK Ss LOYOLA-ICAM Bago tO 110 COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) 1 Close the trace fle and name file and oxeutt the twerk antmection fie. 140 At tho partoulay tre call the finish proudure. (Se Stop tHe Program. Program: a. Unicast Routing Protocol set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue Sns color 2 Red #Open the Trace file set filel [open out.tr w] $ns trace-all $filel #Open the NAM trace file set file2 [open out.nam w] $ns namtrace-all Sfile2 #Define a ‘finish’ procedure proc finish {} { global ns file! file: Sns flush-t cl 1 close Sfile2 exec nam out.nam & exit 3 # Next line should be commented out to have the static routing Sns rtproto DV #Create six nodes set n0 [$ns node] set nl [$ns node] set n2 [Sns node] 311120205017 BHUVANESH RAAM CK ©) LOYOLA-IcAM =" 5 6 COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET) ‘xp.no: 10 Date: 26419622 Simulation of error correction code (like CRC) Aim: To Tenplemunt Lyror chuck? code ding jor. Algorithm: 's Glavt the Program, 2+ Gun @ brt ahthg, append. ©S +o the enol of He Let BUD be the polynomial co rvesporeling to B. 2. Dive BOD bY some “greed on plelynenifal FW and Qrarote, determine the YumaPndsy 20) . Thre den a ao Defe TO) = BOD — BID 5 OT fon Fy 4o be done using rned 2 OD /00 => Umatndes ©) 6s TrangmPt T. i > the Vt strfng & nel Tt). eng Or reperding 40 Te let T vepresent the bE stam thy teary ts 311120205017 BHUVANESH RAAM CK or N LOYOLA-ICAM ee : COLLEGE OF ENGINEERING AND TECHNOLOGY (LICE qT) and T'GD the aseoctitdl. polyrternites |. The veahuer dividus TiO) by G+ Th thre 16 4 ori mdindts, the FeLePvey concludys T= and no errer OCU td | else the reaver woncludlg an exror which requis VW vavanniesion. $* Stop the preqrarn Program: import java.io.BufferedReader; import java.io. IOException; import java.io.InputStreamReader; class erc_gen { public static void main(String args{]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int{) data; int{] div; int{] divisor, int{] rem; int{] ere; int data_bits,Afvisor_bits, tot_length; ‘System.opeprintIn( "Enter number of data bits : "); data iG = Integer.parselnt(br.readLine()); data = new int{data_bits); System.out.printin("Enter data bit for (int i= 0; i < data_bits; i++) datafi) = Integer.parselnt(br.readLine()); ‘System.out.printIn(""Enter number of bits in divisor :"); divisor_bits = Integer.parselnt(br.readLine()); divisor = new int{divisor_bits); System.out.printin("Enter Divisor bits : "); for (int i = 0; i < divisor_bits; i+) divisor[i] = Integer.parseInt(br.readLine(); 311120205017 BHUVANESH RAAM CK

You might also like