Reputation: 3275
I'm working on a solution that requires a webpage to print raw data onto a connected printer. One option is to send the data to the printer through a process, running on the same machine as the browser. The process listens on a specific port and forwards the data from the browser to the printer.
Is it possible to send data from a webpage to another listening process using Websockets?
Upvotes: 3
Views: 2693
Reputation: 69663
Websockets can send to any port, not just port 80. But unfortunately Websockets don't transport raw data. Before the connection is established, a Websocket handshake is performed, which also includes a 32-bit masking key which is XORed with the data stream from the client. That data-stream is also framed by some additional bytes. Details can be found in the RFC.
This unfortunately means that a Websocket client can not communicate with a service which does not support the Websocket protocol. So you will need a middleware which accepts the users websocket connection, unpacks the data stream and forwards it to the printer.
One such middleware is Websockify.
Upvotes: 4