使用套接字打印原始文本

时间:2018-06-09 18:06:55

标签: java android sockets

我正在开发一个应用程序来打印到我当地的无线打印机,但超过9100端口我没有回复,超过515我已经拒绝连接"。

代码是这样的:

Socket test = new Socket();
Socket sock = new Socket(ip,9100);
PrintWriter oStream = new PrintWriter(sock.getOutputStream());

oStream.printf("========================\n");
oStream.printf("PROVA STAMPA\n");
oStream.printf("HELLO SLOW SUD\n");
oStream.printf("========================"+"\n");

oStream.close();
sock.close();

我也试过这个:

Socket objSocket = new Socket();

InetSocketAddress objEndPoint = new InetSocketAddress(ip, 9100);

DataOutputStream objOutputStream;

objSocket.connect(objEndPoint, 6000);

objOutputStream = new DataOutputStream(objSocket.getOutputStream());
objOutputStream.write(("========================\nPROVA STAMPA\nHELLO SLOW SUD\n========================\n").getBytes());

objOutputStream.close();
objSocket.close();

0 个答案:

没有答案