@Override
	public void run() {
		
		try {
			serversocket = new ServerSocket(port);
		} catch (IOException e1) {
			JOptionPane.showMessageDialog(null, "Failed to run serversocket.", "Error", JOptionPane.ERROR_MESSAGE);
			return;
		}
		
		while (breakflag == false) {
			try {
				client = serversocket.accept();
				BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
				PrintWriter writer = new PrintWriter(client.getOutputStream(), true);
				
				//String line = reader.readLine();
				//textField.append(line + "\r\n");
				String line = reader.readLine();
				while(line != null) {
					textField.append(line + "\r\n");
					line = reader.readLine();
				}
				
				writer.close();
				reader.close();
				client.close();
			} catch (IOException e1) {
				JOptionPane.showMessageDialog(null, "Server closed.", "Alert", JOptionPane.WARNING_MESSAGE);
				return;
			}
		}
		
		breakflag = false;
		try {
			serversocket.close();
		} catch (IOException e) {
			JOptionPane.showMessageDialog(null, "Failed to stop serversocket.", "Error", JOptionPane.ERROR_MESSAGE);
		}
		
		JOptionPane.showMessageDialog(null, "Break.", "Alert", JOptionPane.WARNING_MESSAGE);
		return;
	}