Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //client
- private static void menu(Client client) throws IOException, InterruptedException, ClassNotFoundException {
- reader = new BufferedReader(new InputStreamReader(System.in));
- String clientCommand = null;
- String serverOutput;
- try {
- clientCommand = reader.readLine();
- } catch (IOException e) {
- }
- switch (clientCommand) {
- case "1":
- oos.writeUTF(clientCommand);
- Student newStudent = createNewStudent();
- oos.writeObject(newStudent);
- oos.flush();
- Thread.sleep(1000);
- serverOutput = (String) ois.readObject();
- System.out.println(serverOutput);
- menu(client);
- break;
- // ...
- }
- }
- public static Student createNewStudent() {
- Scanner in = new Scanner(System.in);
- String name = in.nextLine();
- System.out.println("faculty: ");
- String faculty = in.nextLine();
- Student student = new Student(name, faculty);
- return student;
- }
- //server
- public void serverHandler() {
- try {
- Socket socket = server.accept();
- ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
- ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
- while (!socket.isClosed()) {
- String message = (String) ois.readObject();
- if (message.equalsIgnoreCase("1")) {
- Student s = (Student) ois.readObject();
- archive.add(s);
- oos.writeObject("the student has been added");
- oos.flush();
- }
- }
- //close etc..
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement