Dobrý den, potřeboval bych poradit jak v Androidu pošlu požadavek na tiskárnu po TCP Port 9100.
Můj pokus:
class SendPrint extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
Log.e("pritning", "start");
// ///////////
Socket socket = null;
OutputStream output = null;
BufferedReader reader = null;
// /////////
try {
socket = new Socket("192.168.1.5", 9100);
socket.setSoTimeout(5000);
output = socket.getOutputStream();
reader = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
} catch (UnknownHostException | SocketException e) {
} catch (IOException e) {
Log.e("pritning", "catch");
e.printStackTrace();
}
// ///////
if (socket != null && output != null) {
try {
Log.e("pritning", "yes");
String message = "asdasdasd";
output.write(message.getBytes());
output.flush();
socket.shutdownOutput();
String response = reader.readLine();
System.out.println(response.toString());
output.close();
socket.close();
} catch (Exception e) {
System.out.println(e.toString());
}
}
return "";
}
}