Whether shared state or RPC is appropriate depends on the nature of the data being transmitted, but if the information transmitted needs to be retained on the client over a page refresh, you should probably use shared state. You’ll probably find shared state more appropriate in most cases, and server-client RPC extremely useful in a few cases.

    To set up server-client RPC, we need to create an interface extending for the RPC methods, then register an implementation of the RPC interface in the client-side connector, and call the method(s) via a proxy on the server. This is the reverse of the server-client RPC described in a separate article.

    We’ll create MyComponentClientRpc in the client package:

    Again, note that the RPC methods can not return anything, but can take multiple arguments.

    In MyComponentConnector we register the RPC implementation in the constructor. This time we’ll create the implementation inline:

    Java

    Finally, in MyComponent we use the RPC via a proxy:

    Java

    That is: every fifth time the label is clicked, we get the RPC proxy by calling getRpcProxy() and call our method with a message to send to the client.