JavaScript-connect printer with WebSocket via JS for printing problems

Source: Internet
Author: User
Through JS with WebSocket to connect the printer to print, known that the printer port is open by default, through the PHP code

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

This printing is possible, but through the JS WebSocket connection only print the header information, 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("连接成功");    ws.send('2222222222222222222222222222');};ws.onclose = function(e) {    console.log("连接关闭");};ws.onerror = function(e) {    console.log("出现错误");};

JS here is not going to Ws.open

Reply content:

Through JS with WebSocket to connect the printer to print, known that the printer port is open by default, through the PHP code

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

This printing is possible, but through the JS WebSocket connection only print the header information, 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("连接成功");    ws.send('2222222222222222222222222222');};ws.onclose = function(e) {    console.log("连接关闭");};ws.onerror = function(e) {    console.log("出现错误");};

JS here is not going to 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 the need for handshake verification, you can take a look at the TCP protocol three times and WebSocket and PHP socket communication

  • 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.