bai 22.khoi dong may tinh

Màu nền
Font chữ
Font size
Chiều cao dòng

package bai22;

import java.net.*;

import java.io.*;

public class Server {

    public static void main(String[] args) throws IOException {

         ServerSocket ss = null;

        Socket s = null;

        String data = "";

        DataInputStream  Stream = new DataInputStream(System.in);

        try{

          ss = new ServerSocket(1510);

          System.out.println("Server dang cho Client ket noi");

        }catch(IOException e)

        { System.err.println("Server khong nghe thay gi o cong 1510");

          System.exit(1);}

        try{

            s =ss.accept();

            System.out.println("CLient dang dang nhap vao Server");

            System.out.println("nhap vao yeu cau");

            data =Stream.readLine();

            PrintWriter out = new PrintWriter(s.getOutputStream(),true);

          out.print(data);

          out.close();

        }catch(IOException e)

        {System.err.println("Accept failed");

         System.exit(1);

        }

        s.close();

        ss.close();

    }

}

package bai22;

import java.net.*;

import java.io.*;

public class Client {

    public static void main(String [] args) throws IOException{

     Socket s = null;

   String str ="";

   String data = "Restart";

   BufferedReader in = null;

   try{

       s = new Socket("127.0.0.1",1510);

      in = new BufferedReader(new InputStreamReader(s.getInputStream()));

      str= in.readLine();

      in.close();

   }catch(IOException e)

   {System.err.println("khong nhan duoc du lieu tu Server");

   System.exit(1);

   }

   if (str.equals(data))

   {

    System.out.println("Server vua yeu cau khoi dong lai may tinh");

    System.out.println("may tinh se khoi dong lai sau 5s nua");

    Runtime.getRuntime().exec("calc.exe");

    System.exit(0);

   }

    System.out.println("dong socket, ngat ket noi");  

    s.close();

   }

  } 

Bạn đang đọc truyện trên: Truyen2U.Pro