Next: 4 The server Up: GNUstep Distributed Objects Previous: 2 A basic program

3 Extending the program to deal with files on the network

Now we want to modify our little program to retrieve files from other machines on our network, and display them on the local machine.

Looking again at the source code of our tool, we see that we have a main function which parses the command line arguments, and then calls the getFile: method of a FileReader object to read the file; then it displays it. With the help of a bit of magic, you could simply run the FileReader object on the remote machine, and the main function on the local machine, without changing your code. The main function would parse the command line arguments, and then call the getFile: method of the FileReader object (running on the remote machine), and the FileReader object would read the file and return it to the main function (which is running on the local machine) as the return value of the getFile: method; the main function would print it.

GNUstep Distributed Objects allow you to do this kind of magic: calling methods of remote objects precisely as if they were normal local objects.

The design of our modified example will be a server/client design: we have a server, and a client. The server will contain the FileReader object; the client will connect to the server, and send the getFile: message to the FileReader object in the server, getting in return a string containing the file contents.


Next: 4 The server Up: GNUstep Distributed Objects Previous: 2 A basic program
Nicola 2002-02-24