Distinct offers Network Monitor, the ONLY natural language Protocol Analyzer, ONC RPC for C++, .NET and Java, and IntelliTerm, the fastest Terminal Emulator for TN3270, TN5250 and VT420 on the market.

Source Code Library

   Products   Downloads   Sales   Support   About us
  Knowledge Base  Ask Cody  Manuals  Source Code Library  Resources



        
 
Product: RPC/XDR Toolkit - for JavaPlatform: JavaLast updated: 11/8/2001
 
Callbacks with JRPC
 
The sample explains how to use callbacks with Distinct RPC for Java. This can be done with the standard package without any modifications.

Again the sample is based on the well-known counter example. This time a new procedure has been added to the cou.x file, named "do_callback":

void do_callback(string host, int progno) = 4;

This procedure instructs the server to call back the client. In order to be able to do that it tells the server the host name and the (transient) program number it should connect to. An unused transient program number has been obtained in quite the same way as the C sample does by calling the static method "CALLBACKServer.getTransient()". Also, a new server object of class "CALLBACKServer", named "callb_server" has been created. This is a full RPC for Java server object with its own threads for serving client (callback) requests.

The server ("docount.java") contains a new thread class that tries to call back a client every 5 seconds. It checks whether a global variable "cb", pointing to a client object (of class "CALLBACK"), has been set to a non-null value and if so it calls it once before destroying the client again (of course, if required, it might call back several times, not just once).

The two stub classes for the callback "CALLBACK" and "CALLBACKServer" have not been created by Jrpcgen directly. Instead most of their basic skeleton comes from running Jrpcgen and they have been modified to accept the program number as an initialization parameter in the constructor. This means, callback programming has to be done currently at the same level of abstraction as the C binding where also no Jrpcgen-generated code but manually created stubs are required.

To run the sample, start "docount" as the server and "testprg <server-host>" as the client. The client will create a new temporary server object, call the "do_callback" procedure, and wait 10 seconds for the server to call back before terminiating. If everything is running properly the server will call back the "inc" procedure within 5 seconds.

The sample code does not handle synchronization issues. To handle more sophisticated tasks using callbacks you have to be aware that the callback at the client site is executed by a separate thread that has to be synchronized with the actions of the other client threads when accessing shared data. This is the major difference to the C-binding where typically everything is focused on the "select" main loop which has no real concurrency.

This sample can be found in the subfolder \samples\callback located under the folder in which you installed the RPC Toolkit for Java.

Download RPC Toolkit for Java
 
 


Samples List


Products

 Network Monitor
The Distinct Network Monitor is a protocol analyzer for Windows that includes both packet sniffing and network traffic statistical analysis tools.

 Intelliterm
The Most Complete Terminal Emulator for TN3270, TN5250 and DEC VT220 to VT420

 RPC for C and C++
The Fastest Way to Port Your Existing Unix-RPC Applications to Windows

  9/5/2008   Legal notices | PRIVACY Policy | Networking News |