1 BHARATH INSTITUTE OF SCIENCE & TECHNOLOGY 173, Agaram Road, Selaiyur, Chennai-600073. Tamil Nadu, India. SCHOOL OF COMPUTING Department of C omputer S cience & E ngineering BACHELOR OF TECHNOLOGY COURSE CODE: U20CSCJ07 NETWORK AND COMMUNICATION LABORATORY RECORD Name of the Student: Batch: 2020-2024 Year: III Term/ Semester: V Section: Register No: DEC 2022 2 BHARATH INSTITUTE OF SCIENCE & TECHNOLOGY 173, Agaram Road, Selaiyur, Chennai-600073, Tamil Nadu, India. Name: Programme: Branch: Year : Semester : Register No: Certified that this is the bonafide record of work done by the above student in the .......................................................................................................................... laboratory during the ................................................. Semester in the Academic Year 2022-2023. Faculty Incharge Head of Department Submitted for the practical Examination held on ................................. Internal Examiner External Examiner 3 INDEX Exp No DATE OF COMPLETION NAME OF THE PROGRAM PAGE NO SIGNATURE OF THE FACULTY 1 Create a socket (TCP) between two computers and enable file transfer between them. 2 Write a socket program to demonstrate Echo/Ping/Talk commands. 3 Write a program to develop a simple Chat Using TCP application. 4 Write a program to develop a simple Chat Using UDP application. 5 Implementation of Stop and Wait Protocol and Sliding Window Protocol. 6 Implementation of DNS, SNMP and File Transfer application using TCP and UDP Sockets. 7 Create a socket for HTTP for web page upload and download. 8 Develop a program to display the client’s address at the server end. 9 Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS 10 Perform a case study about the different routing algorithms to select the network path with itsoptimum and economical during data transfer. i. Link State routing ii. Flooding iii. Distance vector 4 AIM To Perform File Transfer in Client & Server Using TCP/IP. ALGORITHM CLIENT SIDE 1. Start. 2. Establish a connection between the Client and Server. 3. Socket ss=new Socket(InetAddress.getLocalHost(),2000); 4. Implement a client that can send two requests. i) To get a file from the server. ii) To put or send a file to the server. 5. After getting approval from the server ,the client either get file from the server or send 6. file to the server. SERVER SIDE 1. Start. 2. Implement a server socket that listens to a particular port number. 3. Server reads the filename and sends the data stored in the file for the‘get’ request. 4. It reads the data from the input stream and writes it to a file in theserver for the ‘put’ instruction. 5. Exit upon client’s request. 6. Stop. EX.NO:1 Create a socket (TCP) between two computers and enable file transfer between them. DATE: 5 PROGRAM //SERVER import java.io.*; import java.net.*; import java.util.*; import java.text.*; class Pings { public static void main(String args[]) throws IOException { ServerSocket s = new ServerSocket(2000); while(true) { Socket c = s.accept(); InputStream in = c.getInputStream(); InputStreamReader inr = new InputStreamReader(in); BufferedReader br = new BufferedReader(inr); String str = br.readLine(); System.out.println("Ping command received from : "+c.getInetAddress() +" with string "+str); PrintStream ps = new PrintStream(c.getOutputStream()); ps.println(str); if(str.equals("exit")) { break; } } } } //CLIENT import java.io.*; import java.net.*; public class Pingc { 6 public static void main(String args[]) throws IOException { long t1, t2; while(true) { try { Socket soc = new Socket("localhost",2000); InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); System.out.println("Type a string to ping : "); String str = br.readLine(); OutputStream os = soc.getOutputStream(); PrintWriter pw = new PrintWriter(os,true); InputStream in = soc.getInputStream(); InputStreamReader inr = new InputStreamReader(in); BufferedReader br1 = new BufferedReader(inr); t1 = System.currentTimeMillis(); pw.println(str); String str1 = br1.readLine(); t2 = System.currentTimeMillis(); System.out.println("Pinging "+soc.getInetAddress()+" with string "+str ); System.out.println("Reply from "+soc.getInetAddress() +" String "+str1+" Length: "+str1.length()); System.out.println("Sent : "+str.length()+" Received : "+str1.length()+" Lost : "+(str.length()- str1.length())); System.out.println("Approx. Time in Milliseconds = "+(t2-t1)); if(str.equals("exit")) { break; } } catch(Exception e) { 7 System.out.println("Error : "+e.getMessage()); } } } } OUTPUT SERVER 8 CLIENT RESULT Thus the java program for file transfer Operation is done & executed successfully. 9 AIM To write a socket program for Echo /Ping /Talk commands. ALGORITHM CLIENT SIDE 1. Start the program. 2. Create a socket which binds the Ip address of server and the port address to acquire service. 3. After establishing connection send a data to server. 4. Receive and print the same data from server. 5. Close the socket. 6. End the program. SERVER SIDE 1. Start the program. 2. Create a server socket to activate the port address. 3. Create a socket for the server socket which accepts the connection. 4. After establishing connection receive the data from client. 5. Print and send the same data to client. 6. Close the socket. 7. End the program. EX.NO: 2 Create a socket Program for Echo/Ping/Talk commands. DATE: 10 PROGRAM //ECHO SERVER import java.io.*; import java.net.*; import java.lang.*; public class eserver { public static void main(String args[])throws IOException { ServerSocket s=null; String line; DataInputStream is; PrintStream ps; Socket c=null; try { s=new ServerSocket(8080); } catch(IOException e) { System.out.println(e); } try { c=s.accept(); is=new DataInputStream(c.getInputStream()); ps=new PrintStream(c.getOutputStream()); while(true) { line=is.readLine(); System.out.println("msg received and sent back to client"); ps.println(line); 11 } } catch(IOException e) { System.out.println(e); } } } //ECHO CLIENT import java.io.*; import java.net.*; public class eclient { public static void main(String args[]) { Socket c=null; String line; DataInputStream is,is1; PrintStream os; try { c=new Socket("localhost",8080); } catch(IOException e) { System.out.println(e); } try { os=new PrintStream(c.getOutputStream()); is=new DataInputStream(System.in); is1=new DataInputStream(c.getInputStream()); do 12 { System.out.println("client"); line=is.readLine(); os.println(line); if(!line.equals("exit")) System.out.println("server:"+is1.readLine()); }while(!line.equals("exit")); } catch(IOException e) { System.out.println("socket closed"); } } } OUTPUT SERVER 13 CLIENT RESULT Thus the program socket program for Echo /Ping /Talk commands was written & executed successfully. 14 AIM To write a client-server application for chat using TCP. ALGORITHM CLIENT 1. Start the program 2. Include necessary package in java 3. To create a socket in client to server. 4. The client establishes a connection to the server. 5. The client accept the connection and to send the data from client to server. 6. The client communicates the server to send the end of the message 7. Stop the program. SERVER 1. Start the program 2. Include necessary package in java 3. To create a socket in server to client 4. The server establishes a connection to the client. 5. The server accept the connection and to send the data from server to client and vice versa 7. The server communicate the client to send the end of the message. 8. Stop the program. EX.NO:3 Develop a simple Chat Program Using TCP Application. DATE: 15 PROGRAM //SERVER import java.io.*; import java.net.*; public class Server { public static void main(String[] args) throws Exception { ServerSocket sersock = new ServerSocket(3000); System.out.println("Server ready for chatting"); Socket sock = sersock.accept( ); BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in)); // reading from keyboard (keyRead object) OutputStream ostream = sock.getOutputStream(); // sending to client (pwrite object) PrintWriter pwrite = new PrintWriter(ostream, true); InputStream istream = sock.getInputStream();// receiving from server ( receiveRead object) BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream)); String receiveMessage, sendMessage; while(true) { if((receiveMessage = receiveRead.readLine()) != null) { System.out.println(receiveMessage); } sendMessage = keyRead.readLine(); pwrite.println(sendMessage); pwrite.flush(); } } } 16 //CLIENT import java.io.*; import java.net.*; public class Client { public static void main(String[] args) throws Exception { Socket sock = new Socket("127.0.0.1", 3000); // reading from keyboard (keyRead object) BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in)); // sending to client (pwrite object) OutputStream ostream = sock.getOutputStream(); PrintWriter pwrite = new PrintWriter(ostream, true); // receiving from server ( receiveRead object) InputStream istream = sock.getInputStream(); BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream)); System.out.println("Start the chitchat, type and press Enter key"); String receiveMessage, sendMessage; while(true) { sendMessage = keyRead.readLine(); // keyboard reading pwrite.println(sendMessage); // sending to server pwrite.flush(); // flush the data if((receiveMessage = receiveRead.readLine()) != null) //receive from server { System.out.println(receiveMessage); // displaying at DOS prompt } } } } 17 OUTPUT: SERVER CLIENT RESULT Thus the Java program for simple chat using TCP / IP application was written and executed successfully. 18 AIM To write a program to implement simple client-server application using UDP. ALGORITHM CLIENT SIDE 1. Create a datagram socket with server’s IP address. 2. Create datagram packets with data, data length and the port address. 3. Send the datagram packets to server through datagram sockets 4. Receive the datagram packets from server through datagram sockets 5. Close the socket. SERVER SIDE 1. Create a datagram socket with port address. 2. Create datagram packets with data, data length and the port address. 3. Send the datagram packets to client through datagram sockets 4. Receive the datagram packets from client through datagram sockets 5. Close the socket. EX.NO:4 Develop a simple Chat Program Using TCP Application. DATE: 19 PROGRAM //SERVER import java.io.*; import java.net.*; class UDPserver { public static int clientport = 8040,serverport = 8050; public static void main(String args[]) throws Exception { DatagramSocket SrvSoc = new DatagramSocket(clientport); byte[] SData = new byte[1024]; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Server Ready"); while (true) { byte[] RData = new byte[1024]; DatagramPacket RPack = new DatagramPacket(RData,RData.length); SrvSoc.receive(RPack); String Text = new String(RPack.getData()); if (Text.trim().length() == 0) break; System.out.println("\nFrom Client <<< " + Text ); System.out.print("Msg to Client : " ); String srvmsg = br.readLine(); InetAddress IPAddr = RPack.getAddress(); SData = srvmsg.getBytes(); DatagramPacket SPack = new DatagramPacket(SData,SData.length,IPAddr, serverport); SrvSoc.send(SPack); } System.out.println("\nClient Quits\n"); SrvSoc.close(); } } 20 //CLIENT import java .io.*; import java.net.*; class UDPclient { public static DatagramSocket ds; public static int clientport=789,serverport=790; public static void main(String args[])throws Exception { byte buffer[]=new byte[1024]; ds=new DatagramSocket(serverport); BufferedReader dis=new BufferedReader(new InputStreamReader(System.in)); System.out.println("server waiting"); InetAddress ia=InetAddress.getByName("10.0.200.36"); while(true) { System.out.println("Client:"); String str=dis.readLine(); if(str.equals("end")) break; buffer=str.getBytes(); ds.send(new DatagramPacket(buffer,str.length(),ia,clientport)); DatagramPacket p=new DatagramPacket(buffer,buffer.length); ds.receive(p);String psx=new String(p.getData(),0,p.getLength()); System.out.println("Server:" + psx); } } }