Javascript-use javascript to connect to the printer with websocket for printing

Source: Internet
Author: User
Use websocket in js to connect to the printer for printing. the port of the known printer is opened by default. use the PHP code {code ...} this print is acceptable, but only the header information is printed through the websocket connection of JS. what is the situation? The js code is: {code...} js side is not going into... use js to connect to the printer for printing with websocket. it is known that the printer port is opened by default, through PHP code

$s = fsockopen("192.168.1.122", 8081,$errno, $errstr, 30); fwrite($s,"abcjiuejseeeeeeeee2222222222ss");

This print is acceptable, but only the header information is printed through the websocket connection of JS. what is the situation?

The js code is:

Ws = new WebSocket ("ws: // 192.168.1.122: 8081/"); console. log (ws); ws. onopen = function (e) {console. log (e); console. log ("connection successful"); ws. send ('20140901');}; ws. onclose = function (e) {console. log ("connection closed") ;}; ws. onerror = function (e) {console. log ("error ");};

Js cannot access ws. open.

Reply content:

Use websocket to connect to the printer through js for printing. it is known that the port of the printer is opened by default, and PHP code is used.

$s = fsockopen("192.168.1.122", 8081,$errno, $errstr, 30); fwrite($s,"abcjiuejseeeeeeeee2222222222ss");

This print is acceptable, but only the header information is printed through the websocket connection of JS. what is the situation?

The js code is:

Ws = new WebSocket ("ws: // 192.168.1.122: 8081/"); console. log (ws); ws. onopen = function (e) {console. log (e); console. log ("connection successful"); ws. send ('20140901');}; ws. onclose = function (e) {console. log ("connection closed") ;}; ws. onerror = function (e) {console. log ("error ");};

Js cannot access ws. open.

$s = fsockopen("192.168.1.122", 8081,$errno, $errstr, 30);
ws = new WebSocket("ws://192.168.10.120:8081/");

Big Brother, have you found any subtle differences?
192.168.1.122
192.168.10.120

Websocket is based on handshaking verification. you can take a look at the three touch hands of the Tcp protocol and the communication between websocket and PHP socket.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.