ACN Practicals

  • View
    114

  • Download
    7

Embed Size (px)

Text of ACN Practicals

TCP SERVER -------------------------------------------------------------------------------------------------------------

import java.io.*; import java.net.*; class TCPServerFile { public static void main(String args[])throws IOException { int p=0,c; String s,inp; ServerSocket ss=new ServerSocket(2500); Socket soc=ss.accept(); System.out.println("CLIENT AND SERVER CONNECTED!!!"); DataInputStream i=new DataInputStream(soc.getInputStream()); DataOutputStream o=new DataOutputStream(soc.getOutputStream()); File folder = new File("E:/"); File[] listOfFiles = folder.listFiles(); for (File listOfFile : listOfFiles) if (listOfFile.isFile()) {

p++; } o.write(p); o.flush(); for (File listOfFile : listOfFiles) if (listOfFile.isFile()) { o.writeUTF(listOfFile.getName()); o.flush(); } inp=i.readUTF(); FileInputStream fin = new FileInputStream("E:/"+inp); while((c=fin.read())!=-1) { o.write(c); o.flush(); } fin.close(); } }

TCP CLIENT ----------------------------------------------------------------------------------------------------------------

import java.io.*; import java.net.*; import java.util.*; class TCPClientFile { public static void main(String args[])throws IOException { Scanner src=new Scanner(System.in); String inp,rec,list[]; int p=0,ch; Socket s=new Socket(InetAddress.getByName("localhost"),2500 ); System.out.println("CLIENT AND SERVER CONNECTED!!!"); DataInputStream i=new DataInputStream(s.getInputStream()); DataOutputStream o=new DataOutputStream(s.getOutputStream()); list=new String[10]; System.out.println("MENU"); ch=i.read(); for(p=0;p