Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. // Server
  2. import java.io.*;
  3. import java.net.*;
  4.  
  5. public class Server {
  6.     public static void main(String[] args) throws IOException {
  7.  
  8.         ServerSocket ss = new ServerSocket(1201);
  9.         Socket s = ss.accept();
  10.  
  11.         DataInputStream din = new DataInputStream(s.getInputStream());
  12.         DataOutputStream dout = new DataOutputStream(s.getOutputStream());
  13.  
  14.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  15.  
  16.         String msgin="", msgout = "";
  17.  
  18.         while(!msgin.equals("end")) {
  19.             msgin = din.readUTF();
  20.             System.out.println(msgin);
  21.             msgout = br.readLine();
  22.             dout.writeUTF(msgout);
  23.             dout.flush();
  24.         }
  25.         s.close();
  26.     }
  27. }
  28.  
  29.  
  30. // Client
  31. import java.io.*;
  32. import java.net.*;
  33.  
  34. public class Client {
  35.     public static void main(String[] args) throws IOException {
  36.  
  37.         Socket s = new Socket("127.0.0.1",1201);
  38.         DataInputStream din = new DataInputStream(s.getInputStream());
  39.         DataOutputStream dout = new DataOutputStream(s.getOutputStream());
  40.  
  41.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  42.         String msgin="", msgout="";
  43.         while(!msgin.equals("end")){
  44.             msgout = br.readLine();
  45.             dout.writeUTF(msgout);
  46.             msgin = din.readUTF();
  47.             System.out.println(msgin);
  48.         }
  49.  
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement