I have a java code that send text file data to Label printer through IP of LAN, It's Works fine
Can this code be executed on android using okhttp instead?
try {
FileReader fileReader = new FileReader("./src/print.txt");
BufferedReader bufferedReader=new BufferedReader(fileReader);
StringBuilder stringBuilder = new StringBuilder();
String string= "";
while((string=bufferedReader.readLine())!=null){
stringBuilder.append(string).append("\n");
}
bufferedReader.close();
Socket socket=new Socket("10.1.1.1",9100);
OutputStream outputStream=socket.getOutputStream();
outputStream.write(stringBuilder.toString().getBytes());
socket.close();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
CodePudding user response:
No, OkHttp is a HTTP library. It uses Okio java's Socket/SSLSocket for most of the low level IO.
The request above is just a simple TCP socket. You could use Okio operations on top of the socket if you want a nicer API.
Why not just run the code above as is on Android?
