Tue 7 Nov 2006
Modem Dial-Up in Java
Posted by datacrush under Techs
If you need to perform modem dial-up from a Java program running in Windows, you have two choices: Learn port programming or use Windows built-in dialer.
This is how the Java code would look like:
Process prcHdl;
Runtime cmdHdl = Runtime.getRuntime();
String cmd = "rasdial myOffice myUser myPassword";
try {
. prcHdl = cmdHdl.exec(cmd);
. prcHdl.waitFor();
. int prcExit = prcHdl.exitValue();
} catch (Exception ex) {};
Integer prcExit in the sample code above holds return code for the operation. Some of the return codes are:
- 000 - Successful.
- 600 - Operation pending.
- 615 - Port not found.
- 617 - Modem disconnecting.
- 628 - Connection was closed.
- 629 - Connection closed by remote computer.
- 630 - Hardware failure.
- 638 - Request timed out.
If you go to command prompt and type in “rasdial” you’ll get a brief description of passable arguments. It looks like this:
rasdial entryname [username [password|*]] [/DOMAIN:domain] . [/PHONE:phonenumber] [/CALLBACK:callbacknumber] . [/PHONEBOOK:phonebookfile] [/PREFIXSUFFIX]
The entryname comes from Windows dial-up connection that you can create under Network Connections.
To disconnect, you may execute something like this:
Process prcHdl;
Runtime cmdHdl = Runtime.getRuntime();
String cmd = "rasdial myOffice /disconnect";
try {
. prcHdl = cmdHdl.exec(cmd);
. prcHdl.waitFor();
. int prcExit = prcHdl.exitValue();
} catch (Exception ex) {};
This is another blast from the past, one that never made it to production in China because there wasn’t a request from the customer and the project manager didn’t see the benefit of going an extra mile.