Click here to Skip to main content
Click here to Skip to main content
Go to top

Line Printer Daemon in C#

, 16 Jan 2007
Rate this:
Please Sign up or sign in to vote.
A line printer daemon in C#

screenshot of the demo application

Introduction

This article presents a prototype of an LPD server written in C#. LPD stands for Line Printer Daemon. This class enables you to receive a print file sent by an LPR client. This can be an application, see An LPR client in C#, or the command line LPR of Linux or Windows. This class could be a basis for a print server that acts as a front-end for multiple printers, each printer defined by one queue.

Background

The LPR/LPD protocol is a 15+ year old print protocol from the TCP/IP suite that is still widely used in the area of network printers and print servers. It is described in detail in RFC 1179. Augmented variations of the protocol exist, like LPRNG also known as LPR Next Generation.

How it works

When the LPD server is started it reads the configuration file. After the start command it starts to listen on a port, default 515, for a connection. When connection is made by a (LPR)client the LPD server checks if the IP address of the client is allowed to send commands to the server. The core of this selection is an IPMatcher class, which checks if an ip address (IP4) is in a set of predefined ranges. If allowed the LPD server reads the first byte of the network stream to see what command is requested for. The command-set exist of:

  • RESTART: restart the processing of a queue
  • LPR: print a file
  • LPQ: request an overview of jobs in a queue
  • LPRM: removes a job from a queue

The LPD class currently supports the LPR and LPQ commands and accepts the RESTART and LPRM commands.

LPR

When the LPD server receives an LPR command, it checks if a directory associated with the requested queue exists, otherwise it is created. Then the control file and the data file is copied into this directory. The names are typically in the form CFAnnnNAME and DFAnnnNAME, C=control, D=Data, nnn = sequence number, and NAME is a hostname. Note that these names are defined by the LPR client. Further processing of the print file can be done by monitoring the queues/directories.

LPQ

When the LPD server receives an LPQ command, it first checks if the LPQ command is allowed. This is a configuration item that prevents users to see what others print over the network. The LPQ command comes in two flavours, long and short. The LPD class offers a simple implementation for both. If the requested queue does not exists an error message will returned.

LPRM

When the LPD server receives an LPRM command, the server checks if the command is allowed. If not it just acknowledges the request but doesn't do anything. If the command is allowed, the LPRM command should be executed but it is not implemented yet. Hook is ready.

RESTART

When the LPD server receives an RESTART command, the server acknowledges the request but doesn't do anything. If the command is allowed, the command should be executed but it is not implemented yet. Hook is ready.

Points of interest

Before starting the LPD application one must be sure that the Windows TCP/IP Print Service is stopped, as it performs a similar function. The interface of the class resembles a generic service to make it easier to embed the class in a Windows service. To process the LPR command correctly byte counting should be enabled in the TCP/IP port of the printer driver.

As the class is far from ready there are several things to improve. A short list in no specific order (no deadline).

  • improve LPR (support no byte counting)
  • implement LPRM
  • implement RESTART
  • improve LPQ
  • implement more error handling
  • implement backend filter
  • implement status and progress indicators - receiving/idle/%%
  • implement better logging
  • refactor ad fundum

History

  • 2007/01/13 - Version 1.00 - First version of LPD ready to publish.
  • 2007/01/09 - Version 0.00 - Getting started.

Usage rights

Everybody is granted to use this code as long as you refer to the original work, and I would appreciate that enhancements are published at CodeProject too.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

rob tillaart
Web Developer
Netherlands Netherlands
No Biography provided

Comments and Discussions

 
QuestionHow to print pdf and BMP files? PinmemberIbrar Ahmad31-Jan-14 2:12 
GeneralSend character by LPR protocol Pinmembervanhungit29-Mar-10 23:41 
GeneralRe: Send character by LPR protocol Pinmemberrob tillaart30-Mar-10 1:36 
GeneralRe: Send character by LPR protocol Pinmembervanhungit30-Mar-10 15:30 
GeneralRe: Send character by LPR protocol Pinmemberrob tillaart31-Mar-10 0:06 
GeneralRe: Send character by LPR protocol Pinmembervanhungit31-Mar-10 15:42 
GeneralRe: Send character by LPR protocol Pinmemberrob tillaart31-Mar-10 21:06 
GeneralRe: Send character by LPR protocol Pinmembervanhungit5-Apr-10 21:48 
GeneralRe: Send character by LPR protocol Pinmemberrob tillaart5-Apr-10 22:43 
GeneralRe: Send character by LPR protocol Pinmembervanhungit6-Apr-10 15:15 
GeneralRe: Send character by LPR protocol Pinmemberrob tillaart6-Apr-10 21:08 
GeneralRe: Send character by LPR protocol [modified] Pinmemberrob tillaart6-Apr-10 22:00 
GeneralRe: Send character by LPR protocol Pinmembervanhungit7-Apr-10 15:41 
GeneralRe: Send character by LPR protocol Pinmemberrob tillaart7-Apr-10 22:06 
GeneralRe: Send character by LPR protocol Pinmembervanhungit8-Apr-10 15:36 
GeneralRe: Send character by LPR protocol Pinmemberrob tillaart8-Apr-10 20:47 
GeneralGreat job Pinmembergstolarov3-Sep-09 5:56 
General谢谢 Pinmemberylwnet14-Mar-08 3:47 
GeneralRun in WIndows service mode Pinmembermswumei23-Feb-07 3:38 
GeneralStability PinmemberMember #103440621-Feb-07 7:17 
AnswerRe: Stability Pinmemberrob tillaart22-Feb-07 22:11 
GeneralRe: Stability Pinmembermswumei23-Feb-07 2:35 
GeneralBinary mode. PinmemberMember #103440621-Feb-07 6:32 
AnswerRe: Binary mode. Pinmemberrob tillaart22-Feb-07 23:00 
Generalimplemnting this function Pinmembercandarins7-Feb-07 19:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 17 Jan 2007
Article Copyright 2007 by rob tillaart
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid