java - 如何使用打印服务器打印条码?
问题描述
实际上,我想通过打印服务器与打印机连接。我已经编写了一些代码,但我无法连接到该打印服务器的特定打印机。
注意:我可以使用直接 IP 在打印机上连接和打印数据,但由于我们想从打印服务器中选择特定的打印机,我们需要使用公共 IP。
有没有办法从打印服务器连接打印机?如果你能在上面分享一些东西,我将不胜感激。
public static void main (String argv[]) throws Exception
{
// The line below illustrates the default port 6101 for `enter code here`mobile printers 9100 is the default port number
// for desktop and tabletop printers
try{
Socket clientSocket=new Socket("172.xx.xx.xxx",6101);//(host,port)
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
outToServer.writeBytes("^XA");
outToServer.writeBytes("^FO50,50^ADN,36,20^FD Test Print");
outToServer.writeBytes("^FS");
outToServer.writeBytes("^XZ");
clientSocket.close();
}catch(Exception e){
e.printStackTrace();
}
}
解决方案
推荐阅读
- javascript - 有没有办法从分配给外部变量的承诺中得到我的结果?
- typescript - VS代码/w。在 TypeScript Monorepo 中更漂亮
- python - 将一个模型的多个模型实例分配给另一个模型,然后进行比较?
- python - 列出扩展模块而不导入所有
- python - 更改 y 对数刻度 imshow()
- java - 无法从 DataInputStream 读取整个字节数组
- opencv - 在 Raspberry Pi 上安装 OpenCV 时未定义的引用
- python - python: 上传到云存储给出 InternalServerError: 500 Backend Error
- python - 如何执行client.py和server.py开启蓝牙连接
- javascript - 如何构建一个 chrome 扩展来显示当前谷歌搜索的列表