21.08.2015 Views

Pro

May 1998 - JeffLuther.net

May 1998 - JeffLuther.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A Java Client . . .Continued from page 1about them. For blobs, you just don’t use functions thatassume zero-termination (basically every SalStr* functionexcept SalStrSet/GetBufferLength). The ROB library forCTD allows you to use any kind of string, normal andblob; you just have to use it accordingly.In the Java client code I emulated CTD stringbehavior, appending a termination (“\0”) to outgoingmessages and truncating it from incoming messages.However, this simple approach would limit ROBfunctionality to regular strings; it wouldn’t work forblobs, because the message that arrives on the other sideof the connectionwould be differentfrom the startingone. The solutionwas to duplicate theset/get functions toadd their blobequivalents, wherethe termination isn’tFigure 1. The class structure.used.Passing references to functionsUsing SAL, like C, you can pass a primitive parameter byits reference (pointer) instead of its value. This iscommonly used in SAL to retrieve a string from a functionusing the return code to signal the success or failure of theoperation, since a null string itself could be a valid result.In Java you can’t pass primitives this way. The only thingsthat Java can pass by reference are objects. Actuallythey’re always passed by reference, like SAL does.This means that if you want to pass a string byreference, like I needed to do to rewrite the client code inJava, you’ll have to create a class that contains a stringand use objects created from that class instead of thestring itself. Since I had to use this class anyway, I alsoused it to fix the zero-terminated string problem. I createda class called __cROB_ReturnValue where I store thestring that comes from the ROB server and where thefunctions reside that extract a valid Java string, removingthe termination or the unmodified blob string.Class structureThe library (maybe I should call it “package,” as Javawould) is composed of three classes (see Figure 1):• _cROB_CommunicatorClient• _cROB_returnValue• ROB_Client(I didn’t use the “c” prefex for ROB_Client because ofJava’s naming conventions.)The __cROB_CommunicatorClient is responsible forthe connection procedures: It connects, disconnects, andsends and receives messages to and from the connectedROB server.The __cROB_ReturnValue class handles the incomingmessages. It stores theincoming value andinterprets the returncode and removes thezero termination, ifnecessary.ROB_Client is theactual class that you’llhave to use. It handlesall the services that aROB client needs inorder to access remote members and to execute remoteprocedures.ROB_Client references __cROB_CommunicatorClient(it’s a class variable), and both have an instanceconnection with __cROB_ReturnValue since they use it asa parameter.Java’s implementation of the WinsockUsing the Winsock in Java is enormously simpler thanusing it in any Windows development environment(unless, of course, you’re using some third-party library,OCX, VBX, DLL, or anything else between you and theWinsock). In Java you simply create a socket object fromthe Socket class, an input stream object and an outputstream object, bind everything together, and voila! itworks. You don’t have any blocking or non-blocking orsynchronous or asynchronous problems. Everythingworks; after all, Java was primarily developed fornetworking operations.Rally ’Round . . .Continued from page 2Happy talk from Wall StreetCentura has faxed out reprints of an article that ran in theMarch 4th issue of the Wall Street Journal, which notedthat new management has fixed many of the fundamentalfinancial problems that had been plaguing the company.They indicate that the stock may be worth looking at for aspeculative purchase. What do you think? I’d be interestedin the opinions of some long-term Centura investors. CPhttp://www.<strong>Pro</strong>Publishing.comCentura <strong>Pro</strong> May 1998 3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!