Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.ServerSocket;
  3. import java.net.Socket;
  4. import java.nio.ByteBuffer;
  5. import java.nio.charset.StandardCharsets;
  6.  
  7. public class SMTPServer {
  8.     public static void main(String[] args) {
  9.         while (true) {
  10.             try (ServerSocket serverSocket = new ServerSocket(25)) {
  11.                 Socket client = serverSocket.accept();
  12.                 System.out.println("Accepted!");
  13.                 BufferedReader clientIn = new BufferedReader(new InputStreamReader(client.getInputStream()));
  14.                 BufferedWriter clientOut = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
  15.                 clientOut.write("220 OK\r\n");
  16.                 clientOut.flush();
  17.                 String inputLine;
  18.  
  19.                 char[] buffer = new char[1024];
  20.                 int count;
  21.                 while ((count = clientIn.read(buffer)) != -1) {
  22.                     System.out.println(buffer);
  23.                     clientOut.write("250 OK\r\n");
  24.                     clientOut.flush();
  25.                 }
  26.  
  27.                 clientOut.write("250 OK\r\n");
  28.                 clientOut.flush();
  29.  
  30.                 inputLine = clientIn.readLine();
  31.                 System.out.println(inputLine);
  32.                 inputLine = clientIn.readLine();
  33.                 System.out.println(inputLine);
  34.                 inputLine = clientIn.readLine();
  35.                 System.out.println(inputLine);
  36.                 inputLine = clientIn.readLine();
  37.                 System.out.println(inputLine);
  38.             } catch (Exception e) {
  39.                 System.out.println(e.getMessage());
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement