@Override
    public void run() {
        try {
            int iType;
            while (!myThread.isInterrupted() && (iType = iStream.read()) > 0) {
                byte type = (byte) iType;
                if (type == MessageType.BYE.getId()) {
                    close(false, false);
                } else if (type == MessageType.MESSAGE.getId()) {
                    getMessage();
                } else if (type == MessageType.ERROR.getId()) {
                    close(false, false);
                } else {
                    close(true, true);
                }
            }
        } catch (Exception e) {
            if (!myThread.isInterrupted()) {
                close(true, true);
            }
        }
    }