Skip to content
This repository was archived by the owner on Oct 18, 2025. It is now read-only.

3.3 Receive Messages

AlexTape edited this page May 11, 2015 · 2 revisions

Receive Messages

To receive messages sent by the backend you have to bind a custom handler to your main stage. The API provides an abstract class that implements an EventHandler for incoming messages. To get it working, just insert this code to your derived JavaFX Application Class.

/**
 * UniBoxClient: bind event handler for incoming messages.
 */
ClientProvider.bind(primaryStage, new IncomingMessageHandler() {

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * de.unibox.client.api.IncomingMessageHandler#handle(java.lang.
	 * String, java.lang.String)
	 */
	@Override
	public void handle(final String user, final String msg) {

		// handle incoming messages here on <MainThread>

	}
});

All incoming messages will be published within the handle() method, where user contains the sender name and msg the concrete payload (i.e. the message string).

Clone this wiki locally