Advertisement
vencinachev

ServerDemo

Nov 23rd, 2021
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.PrintStream;
  3. import java.net.ServerSocket;
  4. import java.net.Socket;
  5. import java.util.Scanner;
  6.  
  7. public class ServerDemo {
  8.  
  9.     public static void main(String[] args) throws IOException {
  10.         String msg;
  11.         System.out.println("Server is waiting for request....");
  12.         ServerSocket server = new ServerSocket(1211);
  13.         Socket socket = server.accept();
  14.         Scanner scan = new Scanner(socket.getInputStream());
  15.         PrintStream printout = new PrintStream(socket.getOutputStream());
  16.         msg = scan.nextLine();
  17.         if (msg.equalsIgnoreCase("uktc")) {
  18.             printout.println("Server response: Bravo UKTC is right answer!");
  19.         } else {
  20.             printout.println("Server response: Sorry! " + msg + "  is wrong answer!");
  21.         }
  22.         System.out.println("Responsed!");
  23.         server.close();// with this line server would be stoped;
  24.         scan.close();
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement