by John D. Mitchell

Java Tip 6: Java development and testing without a network

news
Apr 1, 19965 mins
Core JavaDeveloperJava

One approach to testing applets involving multiple machines and network accesses on your home PC.

I came out. I am getting there slowly but surely. I am still not getting paid to develop Java code (my job is mainly user support), but there is an unwritten rule in my team to keep up to date with new languages.

So, got my first applets working and the occasional application. Then came networking. I developed a browsing system for our intranet, so that all users could view the weather data available. Now this data ranges from raw observations through to GIFs of numerical model products. This data also resides on many different machines. Some on HP workstations, some on the IBM mainframe and a little on PCs. It was easy to build a system of HTML pages that resided on my HP but loaded graphics from other machines. It was also quite easy to pull data off the IBM and present it as pre-formatted text on a HTML page.

Now this worked well for a while. But as the Java got a bit easier, I started pulling the data in from other machines and started manipulating it (overlays, scaling, color changes). This worked OK. However, I do a lot of my work at home as well. The Java code development was OK. But got to trying to use the Borland Debugger and found out you really do need TCP/IP on the machine and working. Also, found I could do with a Web server on the home machine for testing applets. Iโ€™m using Win95 at home and at work, and I found the TCP/IP very easy to use on the work machine.

So I tried to set up TCP/IP at home, but it wouldnโ€™t go. I found I needed either a modem or a network card. I have neither at home. Got to work the next day and โ€œborrowedโ€ a network card, a standard SMC Ethernet adaptor. Took that home, slapped it into the machine and got the networking working no problem. Got it down to just TCP/IP loaded (Win95 installs IPX/SPX as well, just remove it). In the TCP/IP setup, I gave my home machine 151.170.1.101 for the IP number. My host file is shown below:

# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
127.0.0.1       localhost   
151.170.1.101   techie      # My work PC
151.170.1.101   pthp        # My HP 712
151.170.1.101   atlas       # Satellite Imagery HP 712
151.170.1.101   fr0400      # Text forecasts HP 712
151.170.1.101   fr0700      # Mesoscale model products HP 712
151.170.1.101   vulcan      # Limited Area Model products HP 712

With this setup, I installed a HTTP daemon (settled on NCSAโ€™s) and told it the machine was called techie. This is the same as my work machine. I setup a file structure in the root directory of the HTTPd so that I could browse like I can at work.

For example, my home page at work is kept on my HP pthp. The URL is: http://pthp/bob/home.html. This page also loads a graphic from my PC at work, techie with the line:

With the setup I now have at home it is possible to mirror this behavior with the above HOSTS file. In my HTDOCS directory for the HTTPd I have two directories, bob and status:

|
|
`--HTDOCS
     |
     |--<b>bob</b>       Directory on <b>pthp</b>
     |
     `--<b>status</b>    Directory on <b>techie</b>

As far as Netscape is concerned, it loads the page home.html from the directory bob on pthp and parses the page then goes and gets and then displays the graphic recent.gif from the directory status on techie. Even the HTTPd logs reflect this.

This works just as well for whole systems using HTML, Java applets, JavaScript and CGI-bin scripts. Even better, Borland Debugger works fine. The only problem is that if you have an applet that loads from pthp and then while running trys to fetch data from the machine fr0400, it works. Now this shouldnโ€™t work, as applets can only get data from the machine they were retrieved from. But because all these โ€œvirtualโ€ machines are using the same IP number it works.

However, I think the benefits outweigh this small problem. I can build and test systems at home just like if I was at work. This is great when I have an idea at 2 am on Saturday. It means you can just boot up and go.

I would guess most people who are developing Java on their home machines are using Win95. So the only thing they need is a network card, as all the software is on the Win95 disks. Of course, if you wish to run a Web server as well you can download it.

I showed this to a friend at work and he asked โ€œWhere am I going to get a network card from ?โ€. Good question. You could buy oneโ€ฆ Nah!! I went up to PC support and asked if anyone had a spare card they could forget they ever had. Walked out with a card. No problem.

If that approach doesnโ€™t work, check under desks, on top of filing cabinets, etc. Find that old PC collecting dust and โ€œborrowโ€ the network card on a semi-permanent basis.

Only problem is, how do I fit a mirror of all my work machines onto a floppy to take home? I donโ€™t. I just take home the files I need. As long as the directory structure for each machine is in place it works fine.

Why havenโ€™t the major network card makers made a cheap network card just for this purpose? They could remove all the hardware for actually talking to the bit of cable and make it cost say ยฃ20 (sterling) or less.

Donโ€™t try to access any of the machines mentioned in this article, as they exist behind a firewall and the numbers are different.

Ian Watkins | 11th March 1996 | iwatkins@meto.govt.uk