Androidフォンをプリンターとして使用しようとしています。印刷するドキュメントを受信するために ServerSocket を使用しています。IP アドレスとポートを指定して電話を IP プリンターとして追加し、Generic Postscript Printer を選択すると、ファイルを ps 形式で正しく受信できます。電話をプリンターとして IP プリンターとして追加したくありません。そのため、NsdManager を使用してデバイスをプリンターとして登録しています。Bonjour プリンターとして自動的に認識され、正常にプリンターとして追加できます。しかし今では、コンピューターからドキュメントを印刷するたびに、ソケットの入力ストリームでこのデータを取得します。
POST / HTTP/1.1 Content-Length: 673 Content-Type: application/ipp Host:
Android-2.local:9200 User-Agent: CUPS/2.1.0 (Darwin 15.2.0; x86_64)
IPP/2.0 Expect: 100-continue Gattributes-charsetutf-8Hattributes-
natural-languageen-usEprinter-uriipp://Android-
2.local.:9200/Drequested-attributescompression-supportedDcopies-
supportedDcups-versionDdocument-format-supportedD marker-colorsDmarker-
high-levelsD marker-levelsDmarker-low-levelsDmarker-messageDmarker-
namesDmarker-typesDmedia-col-supportedD$multiple-document-handling-
supportedDoperations-supportedDprint-color-mode-supportedD printer-
alertDprinter-alert-descriptionDprinter-is-accepting-jobsD printer-
mandatory-job-attributesD printer-stateDprinter-state-messageDprinter-
state-reasons
IPP ドキュメントを読み、応答で 100 Continue を送信し、必要なすべてのパラメーターをこのように送信します
clientSocket.setTcpNoDelay(true);
BufferedOutputStream out = new BufferedOutputStream(clientSocket.getOutputStream());
out.write("HTTP/1.1 100\r\n".getBytes("UTF-8"));
out.write("\r\n".getBytes("UTF-8"));
out.write("compression-supported: \"none\"\r\n".getBytes("UTF-8"));
out.write("printer-is-accepting-jobs: \"true\"\r\n".getBytes("UTF-8"));
.....
....
out.flush();
その後、ドキュメントの入力ストリームを読み取ろうとすると、null が返され、コンピューターで「印刷中: プリンターに接続されました」というメッセージが表示されますが、out.close(); を実行すると、ソケットの出力ストリームを閉じるために、コンピューターで「プリンターのステータスを取得できません」というメッセージが表示されます。私を助けてください。この投稿リクエストや正しい応答を送信してドキュメントを取得する方法ではなく、ドキュメントを受信する方法はありますか? 私はこれでかなり長い間立ち往生しています。どんな助けでも大歓迎です。