3.3 Receive Messages - AlexTape/UniBox GitHub Wiki

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).

⚠️ **GitHub.com Fallback** ⚠️