Netcat over Javascript

Viewed 2566

I'm working under one cloud solution, that's allow user to print receipts on ESC/POS printer. So it's actually pretty easy to print on it like

echo "Hello world!" | nc 192.168.1.37 9100

But, I need to do the same with from user's browser. So i've tried like this:

var connection = new WebSocket('ws://IPAddress:Port');

connection.onopen = function () {
  connection.send('Ping'); // Send the message 'Ping' to the server
};

And almost done, but WS send whole stack of HTTP headers starts with

 GET / HTTP/1.1 
 ...

Is there way to send it without headers? Or other way to send data to printer?

2 Answers

netcat or nc use TCP protocol and it doesn't use header like "POST /1 HTTP/1.1\r\n" like http requests do. You are probably thinking about using net.Socket() and not WebSocket I do not want to confuse you because you aim to use javascript in browser, but i used net.Socket() successfully with node.js. The point of this comment is, that you aim to establish TCP connection and not WS.

I think that HTTP always starts sending GET and HTTP Headers. Maybe you can use some old technology like signed Java Applets or Flash. In addition, you can download a binary file to the client PC to communicate.

Related