Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.PrintStream;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.Scanner;
- public class ServerDemo {
- public static void main(String[] args) throws IOException {
- String msg;
- System.out.println("Server is waiting for request....");
- ServerSocket server = new ServerSocket(1211);
- Socket socket = server.accept();
- Scanner scan = new Scanner(socket.getInputStream());
- PrintStream printout = new PrintStream(socket.getOutputStream());
- msg = scan.nextLine();
- if (msg.equalsIgnoreCase("uktc")) {
- printout.println("Server response: Bravo UKTC is right answer!");
- } else {
- printout.println("Server response: Sorry! " + msg + " is wrong answer!");
- }
- System.out.println("Responsed!");
- server.close();// with this line server would be stoped;
- scan.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement