Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- import java.util.*;
- public class ft2client
- {
- public static void main(String srgs[])throws IOException
- {
- Socket s=null;
- BufferedReader get=null;
- PrintWriter put=null;
- try
- {
- s=new Socket("127.0.0.1",8085);
- get=new BufferedReader(new InputStreamReader(s.getInputStream()));
- put=new PrintWriter(s.getOutputStream(),true);
- }
- catch(Exception e)
- {
- System.exit(0);
- }
- String u,f;
- System.out.println("Enter the file name to transfer from server:");
- DataInputStream dis=new DataInputStream(System.in);
- f=dis.readLine();
- put.println(f);
- File f1=new File(f);
- String str = "/home/user/";
- FileOutputStream fs=new FileOutputStream(new File(str,f1.toString()));
- while((u=get.readLine())!=null)
- {
- byte jj[]=u.getBytes();
- fs.write(jj);
- }
- fs.close();
- System.out.println("File received");
- s.close();
- }
- }
- import java.io.*;
- import java.net.*;
- import java.util.*;
- public class ft2server
- {
- public static void main(String args[])throws IOException
- {
- ServerSocket ss=null;
- try
- {
- ss=new ServerSocket(8085);
- }
- catch(IOException e)
- {
- System.out.println("couldn't listen");
- System.exit(0);
- }
- Socket cs=null;
- try
- {
- cs=ss.accept();
- System.out.println("Connection established"+cs);
- }
- catch(Exception e)
- {
- System.out.println("Accept failed");
- System.exit(1);
- }
- PrintWriter put=new PrintWriter(cs.getOutputStream(),true);
- BufferedReader st=new BufferedReader(new InputStreamReader(cs.getInputStream()));
- String s=st.readLine();
- String str = "/home/user/Desktop/";
- String path = str + s;
- System.out.println("The requested file is path: "+path);
- System.out.println("The requested file is : "+s);
- File f=new File(path);
- if(f.exists())
- {
- BufferedReader d=new BufferedReader(new FileReader(s));
- String line;
- while((line=d.readLine())!=null)
- {
- put.write(line);
- put.flush();
- }
- d.close();
- System.out.println("File transfered");
- cs.close();
- ss.close();
- }
- }
- }
- import java.io.*;
- import java.net.*;
- import java.util.*;
- public class ft2server
- {
- public static void main(String args[])throws IOException
- {
- ServerSocket ss=null;
- try
- {
- ss=new ServerSocket(8085);
- }
- catch(IOException e)
- {
- System.out.println("couldn't listen");
- System.exit(0);
- }
- Socket cs=null;
- try
- {
- cs=ss.accept();
- System.out.println("Connection established"+cs);
- }
- catch(Exception e)
- {
- System.out.println("Accept failed");
- System.exit(1);
- }
- BufferedOutputStream put=new BufferedOutputStream(cs.getOutputStream());
- BufferedReader st=new BufferedReader(new InputStreamReader(cs.getInputStream()));
- String s=st.readLine();
- String str = "/home/milind/Desktop/";
- String path = str + s;
- System.out.println("The requested file is path: "+path);
- System.out.println("The requested file is : "+s);
- File f=new File(path);
- if(f.isFile())
- {
- FileInputStream fis=new FileInputStream(f);
- byte []buf=new byte[1024];
- int read;
- while((read=fis.read(buf,0,1024))!=-1)
- {
- put.write(buf,0,read);
- put.flush();
- }
- //d.close();
- System.out.println("File transfered");
- cs.close();
- ss.close();
- }
- }
- }
- import java.io.*;
- import java.net.*;
- import java.util.*;
- public class ft2client
- {
- public static void main(String srgs[])throws IOException
- {
- Socket s=null;
- BufferedInputStream get=null;
- PrintWriter put=null;
- try
- {
- s=new Socket("127.0.0.1",8085);
- get=new BufferedInputStream(s.getInputStream());
- put=new PrintWriter(s.getOutputStream(),true);
- String f;
- int u;
- System.out.println("Enter the file name to transfer from server:");
- DataInputStream dis=new DataInputStream(System.in);
- f=dis.readLine();
- put.println(f);
- File f1=new File(f);
- String str = "/home/milind/";
- FileOutputStream fs=new FileOutputStream(new File(str,f1.toString()));
- byte jj[]=new byte[1024];
- while((u=get.read(jj,0,1024))!=-1)
- {
- fs.write(jj,0,u);
- }
- fs.close();
- System.out.println("File received");
- s.close();
- }catch(Exception e)
- {
- e.printStackTrace();
- System.exit(0);
- }
- }
- }
- Server {
- ...
- soc = echoServer.accept();
- out = new DataOutputStream(soc.getOutputStream());
- out.flush();
- in = new DataInputStream(soc.getInputStream());
- out.writeBytes("some text in here n");
- out.flush();
- ...
- }
- Client{
- ...
- soc = new Socket("10.210.13.121", 62436);
- out = new DataOutputStream(soc.getOutputStream());
- out.flush();
- in = new DataInputStream(soc.getInputStream());
- ...
- while(true)
- if(in.available() > 0)
- String str = in.readLine();
- ...
- }
- import java.io.*;
- import java.net.*;
- import java.util.*;
- public class ft2server
- {
- public static void main(String args[])throws IOException
- {
- ServerSocket ss=null;
- try
- {
- ss=new ServerSocket(8085);
- }
- catch(IOException e)
- {
- System.out.println("couldn't listen");
- System.exit(0);
- }
- Socket cs=null;
- try
- {
- cs=ss.accept();
- System.out.println("Connection established"+cs);
- }
- catch(Exception e)
- {
- System.out.println("Accept failed");
- System.exit(1);
- }
- PrintWriter put=new PrintWriter(cs.getOutputStream(),true);
- BufferedReader st=new BufferedReader(new InputStreamReader(cs.getInputStream()));
- String s=st.readLine();
- String str = "/home/milind/Desktop/";
- String path = str + s;
- System.out.println("The requested file is path: "+path);
- System.out.println("The requested file is : "+s);
- File f=new File(path);
- if(f.isFile())
- {
- BufferedReader d=new BufferedReader(new FileReader(f));
- String line;
- while((line=d.readLine())!=null)
- {
- put.write(line);
- put.flush();
- }
- d.close();
- System.out.println("File transfered");
- cs.close();
- ss.close();
- }
- }
- }
- import java.io.*;
- import java.net.*;
- import java.util.*;
- public class ft2client
- {
- public static void main(String srgs[])throws IOException
- {
- Socket s=null;
- BufferedReader get=null;
- PrintWriter put=null;
- try
- {
- s=new Socket("127.0.0.1",8085);
- get=new BufferedReader(new InputStreamReader(s.getInputStream()));
- put=new PrintWriter(s.getOutputStream(),true);
- String u,f;
- System.out.println("Enter the file name to transfer from server:");
- DataInputStream dis=new DataInputStream(System.in);
- f=dis.readLine();
- put.println(f);
- File f1=new File(f);
- String str = "/home/milind/";
- FileOutputStream fs=new FileOutputStream(new File(str,f1.toString()));
- while((u=get.readLine())!=null)
- {
- System.out.println(u);
- byte jj[]=u.getBytes();
- fs.write(jj);
- }
- fs.close();
- System.out.println("File received");
- s.close();
- }catch(Exception e)
- {
- e.printStackTrace();
- System.exit(0);
- }
- }
- }
Add Comment
Please, Sign In to add comment