Advertisement
Eternoseeker

Server Side STOP

Apr 10th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | Source Code | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. public class Server {
  5.     public static void main(String args[])throws Exception{
  6.         ServerSocket ss = new ServerSocket(3332);
  7.         Socket s = ss.accept();
  8.         DataInputStream din = new DataInputStream(s.getInputStream());
  9.         DataOutputStream dout = new DataOutputStream(s.getOutputStream());
  10.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  11.  
  12.         String str = "", str2 = "";
  13.         while(!str.equals("stop")){
  14.             str = din.readUTF();
  15.             System.out.println("Client says: " + str);
  16.             str2 = br.readLine();
  17.             dout.writeUTF(str2);
  18.             dout.flush();
  19.         }
  20.         din.close();
  21.         s.close();
  22.         ss.close();
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement