简体   繁体   English

收听9100打印

[英]Listen on 9100 for print

How can i listen to raw printer port 9100 in Java. 我该如何用Java监听原始打印机端口9100。

When i create ServerSocket on port 9100 and accept connection nothing happens when i try to print to this port. 当我在端口9100上创建ServerSocket并接受连接时,当我尝试打印到此端口时什么也没有发生。

System.out.println("listening on 9100");
    try {
        ServerSocket serverSocket = new ServerSocket(9100);
        serverSocket.setSoTimeout(0);
        serverSocket.accept();
        System.out.println("Accepted connection");
    } catch (IOException e) {
        e.printStackTrace();
    }

EDIT: "Accepted connection" is never printed. 编辑:永远不会打印“接受的连接”。 So the socket is never initiated 因此套接字永远不会启动

You're ignoring the return value from serverSocket.accept() . 您将忽略serverSocket.accept()的返回值。
This gives you back a socket. 这为您提供了一个插座。 Seems you're not using it at all. 似乎您根本没有使用它。

ServerSocket.accept 的ServerSocket.accept

From that socket you then need to get input/output streams, 然后,您需要从该套接字获取输入/输出流,
and then you can communicate with the client over these streams. 然后您可以通过这些流与客户端进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM