简体   繁体   English

如何使用C#实现IPP网关?

[英]How to implement IPP gateway using C#?

I need to develop a Internet Printing Protocol gateway in .Net that will receive the print jobs fired from IOS using the AirPrint client. 我需要在.Net中开发一个Internet打印协议网关,该网关将接收使用AirPrint客户端从IOS触发的打印作业。 The gateway will receive the document fired and release it to the print queue. 网关将接收触发的文档,并将其释放到打印队列中。 I am able to broadcast my print services using the SDK provided by Apple. 我可以使用Apple提供的SDK广播我的打印服务。 However, when I listen on a port to receive network streams of a document, I am not able to detect the end of stream received as the client keeps on sending streams. 但是,当我在端口上侦听以接收文档的网络流时,由于客户端一直在发送流,因此无法检测到接收到的流的结尾。 My guess is we have to read the attributes and respond accordingly, but I have no idea of these attributes. 我的猜测是我们必须阅读属性并做出相应的响应,但是我对这些属性一无所知。 Below is the code that I am currently using: 以下是我当前正在使用的代码:

IPAddress ipAddress = IPAddress.Parse("10.0.0.13");
IPAddress tcpListener = new TcpListener(ipAddress, 631);
tcpListener.Start();
while (true)
{
TcpClient tcpClient = tcpListener.AcceptTcpClient();
byte[] bytes = new byte[2560];
NetworkStream stream = tcpClient.GetStream();

stream.Read(bytes, 0, bytes.Length);
string mstrMessage = Encoding.ASCII.GetString(bytesReceived, 0, bytesReceived.Length);

string Continue = "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 200 OK\r\nCache-Control: no-cache\r\nDate: " + dateTime + "\r\nPragma: no-cache\r\nTransfer-Encoding: chunked\r\nContent-Type: application/ipp\r\n\r\nattributes-charset utf-8 attributes-natural-language en-us compression-supported none printer-is-accepting-jobs true document-format-supported application/pdf\r\n\r\n0\r\n";

bytesSent = Encoding.ASCII.GetBytes(mstrResponse);

stream.Write(bytesSent, 0, bytesSent.Length);
}

You should check the stream.Read for the returning value. 您应该检查流。 stream.Read返回值。 If it isn't zero you have incoming bytes from the TcpClient : 如果不为零,则有来自TcpClient传入字节:

var bytesLength = 0;
do
{
   bytesLength = stream.Read(bytes, 0, bytes.Length);
   if (bytesLength == 0) return;
}
while(bytesLength > 0);

You need to understand the level of communication. 您需要了解沟通的水平。 You're not even reading or writing proper IPP messages yet. 您甚至还没有阅读或编写正确的IPP消息。 100 continue is purley HTTP related. 100继续与purley HTTP有关。

Even though Apples Spec for AirPrint is not publicly available there's still a lot of information online. 即使Apple规格的AirPrint未公开可用,在线上仍然有很多信息。 In short: AirPrint is based on IPP. 简而言之:AirPrint基于IPP。 As for the supported PDL PDF is a good choice but not the only one. 至于受支持的PDL PDF是一个不错的选择,但不是唯一的选择。 iOS first checks the printers capabilities. iOS首先检查打印机功能。 It's up to you what kind of (virtual) print-server you offer. 由您决定提供哪种(虚拟)打印服务器。

(In case you have a business case and require a remote developer, don't hestitate to contact us.) (如果您有业务案例并需要远程开发人员,请立即与我们联系。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM