Home > Backend Development > PHP Tutorial > javascript - Printing problem using websocket to connect printer through js

javascript - Printing problem using websocket to connect printer through js

WBOY
Release: 2023-03-01 16:28:02
Original
4302 people have browsed it

Use websocket to connect to the printer through js for printing. It is known that the printer port is open by default, through PHP code

<code>$s = fsockopen("192.168.1.122", 8081,$errno, $errstr, 30);
 fwrite($s,"abcjiuejseeeeeeeee2222222222ss");</code>
Copy after login
Copy after login

It is okay to print like this, but only the header information is printed through the websocket connection through JS. What is the situation?

js code is:

<code>ws = new WebSocket("ws://192.168.1.122:8081/");
console.log(ws);
ws.onopen = function (e) {
    console.log(e);
    console.log("连接成功");
    ws.send('2222222222222222222222222222');
};
ws.onclose = function(e) {
    console.log("连接关闭");
};
ws.onerror = function(e) {
    console.log("出现错误");
};</code>
Copy after login
Copy after login

js cannot be entered here ws.open

Reply content:

Use websocket to connect to the printer through js for printing. It is known that the printer port is open by default, through PHP code

<code>$s = fsockopen("192.168.1.122", 8081,$errno, $errstr, 30);
 fwrite($s,"abcjiuejseeeeeeeee2222222222ss");</code>
Copy after login
Copy after login

It is possible to print like this, but only the header information is printed through the JS websocket connection. What is the situation?

js code is:

<code>ws = new WebSocket("ws://192.168.1.122:8081/");
console.log(ws);
ws.onopen = function (e) {
    console.log(e);
    console.log("连接成功");
    ws.send('2222222222222222222222222222');
};
ws.onclose = function(e) {
    console.log("连接关闭");
};
ws.onerror = function(e) {
    console.log("出现错误");
};</code>
Copy after login
Copy after login

js cannot be entered here ws.open

<code>$s = fsockopen("192.168.1.122", 8081,$errno, $errstr, 30);</code>
Copy after login
<code>ws = new WebSocket("ws://192.168.10.120:8081/");</code>
Copy after login

Brother, have you noticed any subtle differences?
192.168.1.122
192.168.10.120

Websocket is based on the need for handshake verification. You can take a look at the three handshakes of the Tcp protocol and the communication between websocket and PHP socket

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template