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>
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>
js cannot be entered here ws.open
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>
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>
js cannot be entered here ws.open
<code>$s = fsockopen("192.168.1.122", 8081,$errno, $errstr, 30);</code>
<code>ws = new WebSocket("ws://192.168.10.120:8081/");</code>
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