[英]How to implement IPP gateway using C#?
我需要在.Net中开发一个Internet打印协议网关,该网关将接收使用AirPrint客户端从IOS触发的打印作业。 网关将接收触发的文档,并将其释放到打印队列中。 我可以使用Apple提供的SDK广播我的打印服务。 但是,当我在端口上侦听以接收文档的网络流时,由于客户端一直在发送流,因此无法检测到接收到的流的结尾。 我的猜测是我们必须阅读属性并做出相应的响应,但是我对这些属性一无所知。 以下是我当前正在使用的代码:
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);
}
您应该检查流。 stream.Read
返回值。 如果不为零,则有来自TcpClient
传入字节:
var bytesLength = 0;
do
{
bytesLength = stream.Read(bytes, 0, bytes.Length);
if (bytesLength == 0) return;
}
while(bytesLength > 0);
您需要了解沟通的水平。 您甚至还没有阅读或编写正确的IPP消息。 100继续与purley HTTP有关。
即使Apple规格的AirPrint未公开可用,在线上仍然有很多信息。 简而言之:AirPrint基于IPP。 至于受支持的PDL PDF是一个不错的选择,但不是唯一的选择。 iOS首先检查打印机功能。 由您决定提供哪种(虚拟)打印服务器。
(如果您有业务案例并需要远程开发人员,请立即与我们联系。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.