Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. //client
  2. private static void menu(Client client) throws IOException, InterruptedException, ClassNotFoundException {
  3. reader = new BufferedReader(new InputStreamReader(System.in));
  4. String clientCommand = null;
  5. String serverOutput;
  6. try {
  7. clientCommand = reader.readLine();
  8. } catch (IOException e) {
  9. }
  10. switch (clientCommand) {
  11. case "1":
  12. oos.writeUTF(clientCommand);
  13. Student newStudent = createNewStudent();
  14. oos.writeObject(newStudent);
  15. oos.flush();
  16. Thread.sleep(1000);
  17. serverOutput = (String) ois.readObject();
  18. System.out.println(serverOutput);
  19. menu(client);
  20. break;
  21. // ...
  22. }
  23. }
  24.  
  25. public static Student createNewStudent() {
  26. Scanner in = new Scanner(System.in);
  27. String name = in.nextLine();
  28. System.out.println("faculty: ");
  29. String faculty = in.nextLine();
  30. Student student = new Student(name, faculty);
  31. return student;
  32. }
  33.  
  34. //server
  35. public void serverHandler() {
  36. try {
  37. Socket socket = server.accept();
  38. ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
  39. ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
  40. while (!socket.isClosed()) {
  41. String message = (String) ois.readObject();
  42. if (message.equalsIgnoreCase("1")) {
  43. Student s = (Student) ois.readObject();
  44. archive.add(s);
  45. oos.writeObject("the student has been added");
  46. oos.flush();
  47. }
  48. }
  49. //close etc..
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement