Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. /*
  2. * Author: Austin Bowmar
  3. * Date: 10/10/2018
  4. * Server Source File
  5. *
  6. */
  7.  
  8. import java.io.*;
  9. import java.net.ServerSocket;
  10. import java.net.Socket;
  11. import java.util.Scanner;
  12.  
  13. public class Server
  14. {
  15. //initialize socket and input stream
  16. private Socket socket = null;
  17. private ServerSocket server = null;
  18. private DataInputStream in = null;
  19.  
  20. // constructor with port
  21. public Server()
  22. {
  23.  
  24. try
  25. {
  26. server = new ServerSocket(50001);
  27. System.out.println("Server started");
  28.  
  29. System.out.println("Waiting for a client ...");
  30.  
  31. socket = server.accept();
  32. System.out.println("Client accepted");
  33.  
  34. // takes input from the client socket
  35. in = new DataInputStream(
  36. new BufferedInputStream(socket.getInputStream()));
  37.  
  38. String line = "";
  39.  
  40. //String[] cliInput = line.split("\\s+");
  41. File file = new File("Users.txt");
  42. Scanner sc = new Scanner(file);
  43. String var = sc.nextLine();
  44. String[] split = var.split("\\s+");
  45.  
  46. String User = split[0];
  47. String Pass = split[1];
  48.  
  49. // reads message from client until "Done" is sent
  50. while (!line.equals("DONE"))
  51. {
  52. try
  53. {
  54. line = in.readUTF();
  55.  
  56. String[] cliInput = line.split("\\s+");
  57.  
  58. switch(cliInput[0]) {
  59. case "USER":
  60. boolean valid = false;
  61.  
  62. while(sc.hasNextLine() && valid != true) {
  63.  
  64. if(split[0].equals( cliInput[1])){
  65. System.out.println("maybe it works.");
  66. valid = true;
  67. }
  68. else{
  69.  
  70.  
  71.  
  72.  
  73. }
  74.  
  75. }
  76. break;
  77. case "PASS":
  78. if(split[1].equals(cliInput[1])){
  79. System.out.println("You may enter.");
  80. }
  81. else{
  82. System.out.println("Nah.");
  83. }
  84. break;
  85. case "LIST":
  86. System.out.println("FUCK3");
  87. break;
  88. case "KILL":
  89. System.out.println("FUCK4");
  90. break;
  91. case "RETR":
  92. System.out.println("FUCK5");
  93. break;
  94. }
  95.  
  96.  
  97. System.out.println(line);
  98.  
  99. }
  100. catch(IOException i)
  101. {
  102. System.out.println(i);
  103. }
  104. }
  105. System.out.println("Closing connection");
  106.  
  107. // close connection
  108. socket.close();
  109. in.close();
  110. }
  111. catch(IOException i)
  112. {
  113. System.out.println(i);
  114. }
  115. }
  116. public static void main(String args[])
  117. {
  118. Server server = new Server();
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement