Monday, November 23, 2015

open & delete file (client)

This is a client file. See the server here.

code:

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;

public class FileSearchClient {

 public static void main(String args[]) {
       try {
          Socket theSocket = new Socket("Write Local IP address here", 8080);
          System.out.println("Connected to server");

          InputStream inputStream = theSocket.getInputStream();
          ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
          OutputStream OutputStream = theSocket.getOutputStream();
          ObjectOutputStream objectOutputStream = new ObjectOutputStream(OutputStream);

          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

          String rcv_msg, send_msg;

          while(true) {
             /* Send a message to Server */
             System.out.print("To Server : ");
             send_msg = br.readLine();
             objectOutputStream.writeObject(send_msg);

             /* Recieve a message from Server */
             System.out.println("Waiting for server to respond ... ");
             if((rcv_msg = (String)objectInputStream.readObject()) != null) {
                System.out.println("\nFrom Server : " + rcv_msg);
             }
          }
       } catch(Exception e) {
          System.out.println(e);
       }
    }
 }