Operating System - HP-UX
1832985 Members
2582 Online
110048 Solutions
New Discussion

Opening sockets to a printer or Printer protocols??

 
Chad Crosby
New Member

Opening sockets to a printer or Printer protocols??

Hi,
I've got a problem with my perl program.

Its supposed to open a socket, send information to the printer (a request for page counts, ect...), and then receive back data.

Currently, I'm not sure Im even using the right protocols, so I was wondering if anyone could tell me how they would do this?

Program:
1. Open a socket to printer (using tcp currently)
2. Ask printer a question (how do I do this??)
3. Read and parse answer.
4. Print answer in a file.
5. close socket.

Thanks for any ideas or help,
Chad
** Don't assume anything **
1 REPLY 1
Gregory Fruth
Esteemed Contributor

Re: Opening sockets to a printer or Printer protocols??

Well, it depends on what you want to ask the
printer, and what it's willing to tell you.

These days a lot of printers have built-in web
servers, so you can communicate with them via
HTTP. You can use Perl's LWP::UserAgent and
HTTP::Request modules to talk to the printer, though
you'll have to parse the HTML output somehow.
Maybe there's a module to help you parse it.

use LWP::UserAgent;
use HTTP::Request;
$url = 'http://printername"
$ua = new LWP::UserAgent;
$req = new HTTP::Request(GET => $url);
$res = $ua->request($req);
if ($res->is_success()) {
$reply = $res->content();
# do something with $reply
}

If the printer doesn't have a built-in web server,
you may still be able to talk to it directly using TCP.
The easiest way is probably to use the TELNET
protocol. You can test this by simply typing
"telnet printername" and seeing what happens.
If you don't get an error message, type "?" or "h"
or something to get a help menu. To exit, you can
usually type "exit" or CTRL-] followed by "q".

If this works, you can probably use Perl's
Net::Cmd module to talk to the printer. I haven't
tried it, so you're on your own.

HTH