gmuth/ipp-client-kotlin

Regarding Socket Timeout

anuj72 opened this issue · 8 comments

getting socket timeout for larger files in ipp
Screenshot 2024-06-02 at 9 07 33 PM

The default timeout is set to 30 seconds. You can customize this configuration like this:

ippPrinter.ippConfig.timeout = Duration.ofMinutes(3)

Which operation do you use to submit the document? For large files I'd recommend the workflow: validate-job, create-job, send-document.

` val filePath = context.externalCacheDir?.path + "/abc.jpg"
val file = File(filePath)
println(filePath)

 //   val imageUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/481px-Cat03.jpg"
   // val imageData = fetchImageAsByteArray(imageUrl)

// println("Image read successfully, byte array size: ${ imageData?.size}")
if (file.exists()) {
try {
// val byteArray = file.readBytes()
// println("File read successfully, byte array size: ${byteArray.size}")
// val arr= readFileAsByteArray(filePath)

            // Do something with the byte array, e.g., send it to a server or save it

            val printer = IppPrinter(URI.create("ipp://172.50.16.200/ipp/printer"))
            printer.ippConfig.timeout = Duration.ofMinutes(10)

            val job1 = printer.printJob(
                file,
                jobPriority(100),
                jobName(file.name),
                DocumentFormat.JPEG,

                notifyEvents = listOf("job-state-changed", "job-stopped", "job-completed") // CUPS
            )
            job1.subscription?.pollAndHandleNotifications { println(it) }
            job1.waitForTermination()

        } catch (e: IOException) {
            e.printStackTrace()
            println("Error reading file: ${e.message}")
        }
    } else {
        println("File does not exist")
    }

`

**i am using like this is there any other way after changing time also printer its showing printing but print is not happening **
IMG_3074

It looks like your printer is unable to handle your print request. Does it respond at all?

Are you sure your printer supports subscriptions and notifications like CUPS does?
It's very common that printers do not process unsupported requests very well. By IPP specification printers should respond with appropriate results like bad-request oder unsupported-attributes - however often they don't.

You really should start with simple print operations like this and then add more options in small steps.

  IppPrinter(URI.create("ipp://172.50.16.200/ipp/printer"))
     .printJob(File("abc.jpg"))

hi for image less than 30kb it printing fine . but for 100kb image its keeps showing printing document then connection timeout comes
Screenshot 2024-06-04 at 6 43 11 PM
i tried to incrase readtimeout that also not working

Please cooperate by answering my questions from above. Also I would like to know what that result of my suggested approach is. Please do not provide screenshots - instead provide the code causing an issue and the stacktrace as text.
This implements IPP - so if the printer does not respond it looks like an IPP implementation issue to be fixed by the printer manufactuer. how ever it's likely that unusual (unsupported) IPP request trigger this behavior.

Please cooperate by answering my questions from above. Also I would like to know what that result of my suggested approach is. Please do not provide screenshots - instead provide the code causing an issue and the stacktrace as text.

hi tried same way you defined with simple

 IppPrinter(URI.create("ipp://172.50.16.200/ipp/printer"))
     .printJob(File("abc.jpg"))

this showing same problem

` if (file.exists()) {
            try {
                val printer = IppPrinter(URI.create("ipp://172.50.16.200/ipp/printer"))
val job1 = printer.printJob(
                    file,
                    DocumentFormat.JPEG
                )
                job1.waitForTermination()

            } catch (e: IOException) {
                e.printStackTrace()
                println("Error  file: ${e.message}")
            }
        } else {
            println("File does not exist")
        }`

Which operation offered by my IPP library is running into the timeout? You really need to provide a full stack trace in text format. In case it's the printJob operation I've already suggest another workflow using sendDocument().

Which operation offered by my IPP library is running into the timeout? You really need to provide a stack trace.

ok sure