Click here to Skip to main content
11,639,554 members (63,230 online)
Click here to Skip to main content

Line Printer Daemon in C#

, 16 Jan 2007 66.6K 2.3K 36
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

You may also be interested in...

Comments and Discussions

 
GeneralRe: Send character by LPR protocol Pin
rob tillaart6-Apr-10 21:08
memberrob tillaart6-Apr-10 21:08 
GeneralRe: Send character by LPR protocol [modified] Pin
rob tillaart6-Apr-10 22:00
memberrob tillaart6-Apr-10 22:00 
GeneralRe: Send character by LPR protocol Pin
vanhungit7-Apr-10 15:41
membervanhungit7-Apr-10 15:41 
GeneralRe: Send character by LPR protocol Pin
rob tillaart7-Apr-10 22:06
memberrob tillaart7-Apr-10 22:06 
GeneralRe: Send character by LPR protocol Pin
vanhungit8-Apr-10 15:36
membervanhungit8-Apr-10 15:36 
GeneralRe: Send character by LPR protocol Pin
rob tillaart8-Apr-10 20:47
memberrob tillaart8-Apr-10 20:47 
GeneralGreat job Pin
gstolarov3-Sep-09 5:56
membergstolarov3-Sep-09 5:56 
General谢谢 Pin
ylwnet14-Mar-08 3:47
memberylwnet14-Mar-08 3:47 
GeneralRun in WIndows service mode Pin
mswumei23-Feb-07 3:38
membermswumei23-Feb-07 3:38 
GeneralStability Pin
Member #103440621-Feb-07 7:17
memberMember #103440621-Feb-07 7:17 
AnswerRe: Stability Pin
rob tillaart22-Feb-07 22:11
memberrob tillaart22-Feb-07 22:11 
GeneralRe: Stability Pin
mswumei23-Feb-07 2:35
membermswumei23-Feb-07 2:35 
GeneralBinary mode. Pin
Member #103440621-Feb-07 6:32
memberMember #103440621-Feb-07 6:32 
AnswerRe: Binary mode. Pin
rob tillaart22-Feb-07 23:00
memberrob tillaart22-Feb-07 23:00 
Generalimplemnting this function Pin
candarins7-Feb-07 19:05
membercandarins7-Feb-07 19:05 
GeneralRe: implemnting this function Pin
rob tillaart17-Feb-07 5:18
memberrob tillaart17-Feb-07 5:18 
QuestionWhere is the Code of this project Pin
Member #102136619-Jan-07 2:10
memberMember #102136619-Jan-07 2:10 
AnswerRe: Where is the Code of this project Pin
Paul Conrad19-Jan-07 4:18
editorPaul Conrad19-Jan-07 4:18 
AnswerRe: Where is the Code of this project Pin
Nishant Sivakumar19-Jan-07 4:46
mvpNishant Sivakumar19-Jan-07 4:46 
GeneralMissin' Source Pin
norm .net16-Jan-07 21:22
membernorm .net16-Jan-07 21:22 
GeneralRe: Missin' Source Pin
Paul Conrad19-Jan-07 4:18
editorPaul Conrad19-Jan-07 4:18 
GeneralRe: Missin' Source Pin
norm .net19-Jan-07 4:42
membernorm .net19-Jan-07 4:42 

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 | Terms of Use | Mobile
Web01 | 2.8.150731.1 | Last Updated 17 Jan 2007
Article Copyright 2007 by rob tillaart
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid