Overview of Computer Networks

Start from the beginning
                                        

type

gcc x.c

as if gcc were on taco's local disk.

How does this work? At boot time, taco is set up to execute shell scripts in files like /etc/rc, /etc/rc.local

and so on. In one of these files, there will be a command like

mount -t nfs rosarita.engr.ucdavis.edu:/usr/pkg /usr/pkg

On the other end, one of rosarita's bootup files will include an export command, saying that it is all right

to allow its directory /usr/pkg to be mounted by other machines. The OS is set up so that if on taco I try to

access a file in /usr/pkg, my request will actually be redirected to rosarita, transparently to me.

Here is why the RPC mechanism is convenient. On a UNIX system, input/output is done via system calls

open(), read(), write() and so on.19 So, in the example above, when a file within /usr/pkg is referenced at

taco (our use of gcc will consist of a read to the file /usr/pkg/gnu/bin/gcc), the function open(), read(), and

so on will then do RPCs to the corresponding functions at rosarita.

5 Network Programming

5.1 TCP Socket Example

Below are two C programs, a client and a server. To explain what they do, suppose the server is running on

machine X and the client on Y. The server will report to the client the load at X (defined by the output of the

UNIX commands w and ps -ax). Suppose for example we compiled the client and server under the names

wps and svr on toto.berkeley.edu and garnacha.engr.ucdavis.edu, respectively. We would run svr on the

latter (probably as a background process), and on the former might test wps as follows:

toto% wps garnacha.engr.ucdavis.edu w

1:01pm up 37 days, 17:54, 2 users, load average: 0.06, 0.00, 0.00

User tty login@ idle JCPU PCPU what

matloff ttyp1 12:58pm 1 4 1 script

matloff ttyp2 1:00pm 1 2 1 w

bslouie ttyp3 11:43am 1 42 13 tin-new

toto%

(Note that my name appeared in the output. This is just a coincidence, arising from the fact that I had

telnet-ed into garnacha from toto in order to start up svr.)

19You might not have used these before, and instead be more familiar with fopen(), fscanf(), fprint(), and so on.

13

5.1.1 Source Code

Here are the programs:

1

2 /* WPsClient.c */

3

4 /* Client for the server for remote versions of the

5 w and ps commands.

6

7 User can check load on machine without logging in

8 (or even without being able to log in).

9

10 Usage: wps remotehostname command (where "command"

You've reached the end of published parts.

⏰ Last updated: May 09, 2009 ⏰

Add this story to your Library to get notified about new parts!

Overview of Computer NetworksWhere stories live. Discover now