@Override
	public void run() {
		while(true) {
			try {
				Object o = in.readObject();
				if(o != null) {
					// new client connected
					// add to list with name and port
					if(o instanceof JoinTransfer) {
						JoinTransfer trans = (JoinTransfer) o;
						LogicalClientsContainer.getInstance().add(new LogicalClient(trans.getName(), trans.getPortSender()));
						
						activity.addPortToChat(trans.getPortSender());
						sendObject(new JoinResponseTransfer(this.getPort(), trans.getPortSender(), this.name));
						
						activity.setConnectedCount(LogicalClientsContainer.getInstance().getAvailableCount());
					
					// client left session
					// remove from list
					} else if(o instanceof LeaveTransfer) {
						LeaveTransfer trans = (LeaveTransfer) o;
						LogicalClientsContainer.getInstance().remove(trans.getPortSender());
						
						activity.removePortFromChat(trans.getPortSender());

						activity.setConnectedCount(LogicalClientsContainer.getInstance().getAvailableCount());
						
					// this client joined
					// existing clients respond with name and port
					} else if(o instanceof JoinResponseTransfer) {
						JoinResponseTransfer trans = (JoinResponseTransfer) o;
						LogicalClientsContainer.getInstance().add(new LogicalClient(trans.getName(), trans.getPortSender()));
						
						activity.addPortToChat(trans.getPortSender());
						
						activity.setConnectedCount(LogicalClientsContainer.getInstance().getAvailableCount());
					} else if(o instanceof FileTransfer) {
						FileTransfer trans = (FileTransfer) o;

						WavSound.play("notif");
						
						trans.store();
					} else if(o instanceof ChatTransfer) {
						ChatTransfer trans = (ChatTransfer) o;

						WavSound.play("notif");
						activity.setVisible(true);
						
						activity.updateChat(trans);
					}
				}
			} catch (Exception e) {
				System.out.println(e.getLocalizedMessage());
				break;
			}
		}
		
		if(!closed) {
			JOptionPane.showMessageDialog(activity, "Server antwortet nicht mehr! :(");
		}
		
		activity.dispose();
		System.exit(1);
	}