123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package com.company;
- import java.io.*;
- import java.net.Socket;
- public class Client extends Thread {
- private Socket socket;
- private InputStream is;
- private OutputStream os;
- /**
- *
- * @param socket сокет клиента
- */
- public Client(Socket socket) throws IOException {
- this.socket = socket;
- this.is = this.socket.getInputStream();
- this.os = this.socket.getOutputStream();
- }
- @Override
- public void run() {
- while (!isInterrupted()) {
- try {
- ObjectInputStream objectInputStream = new ObjectInputStream(is);
- UserMessage userMessage = (UserMessage)objectInputStream.readObject();
- switch (userMessage.TYPE) {
- case DEPOSIT:
- Bank.deposit(userMessage.BALANCE, userMessage.BILL_NUMBER);
- break;
- case WITHDRAW:
- Bank.withdraw(userMessage.BALANCE, userMessage.BILL_NUMBER);
- break;
- case SIGN_CONTRACT:
- Bank.insert(userMessage.PASSPORT, userMessage.PHONE, userMessage.FULLNAME, userMessage.BALANCE);
- break;
- case BREAK_CONTRACT:
- Bank.delete(userMessage.BILL_NUMBER);
- break;
- }
- } catch (ClassNotFoundException | IOException exception) {
- System.out.println(exception.getMessage());
- interrupt();
- }
- }
- try {
- is.close();
- os.close();
- socket.close();
- } catch (IOException exception) {
- System.out.println(exception.getMessage());
- }
- }
- }
|