Need Help on JAVA API
Anonymous
anonymous at easysw.com
Fri Apr 1 08:32:12 PST 2005
Hi,
I am a new user of CUPS. I have written a small cups program in java using cups. jar , sending a print file to CUPS installed in Linux.
When I run the program on the same Linux box, it works fine.
When I run the same program on another Linux or Windows box, it gives socket error in getting printers. This error is not consistant.
I have tried setting client conf file and cupsd conf file as per documentation but I am not able to resolve this error.
Please let me know how to solve this problem.
My program code is as follows:
import java.io.*;
import org.cups.*;
public class WorkerSpooler {
public static void main (String args[])
{
WorkerSpooler ws = new WorkerSpooler();
ws.GetPrinterNames();
ws.GetPrinters();
}
private void GetPrinterNames()
{
URL u1 = null;
Cups cups1 = null;
try
{
u1 = new URL("http://10.65.1.32:631/printers/");
cups = new Cups(u1);
cups.setUser(ApplicationConstants.USER_NAME);
cups.setPasswd(ApplicationConstants.PASSWORD);
String str = cupsNo.toString();
cups.setInstance(str);
cupsNo = new Integer(cupsNo.intValue()+1);
//cups1.setProtocol("http");
printer_names = cups.cupsGetPrinters();
//printer_names = cups.cupsGetDefault(); //This always works. I always get the default printer.
System.out.println("Got printers");
if (printer_names != null)
num_printers = printer_names.length;
else
num_printers = 0;
cups1 = null;
u1 = null;
}
catch (IOException e)
{
e.printStackTrace();
return;
}
}
private void GetPrinters()
{
printers = new CupsPrinter[num_printers];
for (int i=0; i < num_printers; i++)
{
try
{
printers[i] = new CupsPrinter( cups, printer_names[i] );
System.out.println("Default Printer"+i+": "+printers[i].getPrinterName());
}
catch (IOException e)
{
System.out.println("Exception Getting printers");
e.printStackTrace();
return;
}
}
}
}
More information about the cups-devel
mailing list